pyfai documentation · 2019-04-02 · pyfai documentation, release 0.15.0a0 pyfai is a python...
TRANSCRIPT
![Page 1: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/1.jpg)
pyFAI DocumentationRelease 0.15.0a0
Jérôme Kieffer
Aug 23, 2017
![Page 2: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/2.jpg)
![Page 3: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/3.jpg)
Contents
1 General introduction to PyFAI 3
2 Cookbook recipes 15
3 Tutorials 25
4 pyFAI scripts manual 115
5 Design of the Python Fast Azimuthal Integration library 133
6 pyFAI API 137
7 Installation of Python Fast Azimuthal Integration library 247
8 PyFAI Ecosystem 255
9 Project 259
10 ChangeLog of Versions 267
11 List of publication about pyFAI 275
12 Bibliography 277
13 Glossary 279
14 Indices and tables 281
Bibliography 283
Python Module Index 285
i
![Page 4: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/4.jpg)
ii
![Page 5: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/5.jpg)
pyFAI Documentation, Release 0.15.0a0
PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing highperformance thanks to GPU computing. Most concepts have been presented at EuroScipy 2014 in this video aswell as the proceedings.
The documentation starts with a general descriptions of the pyFAI library. This first chapter contains an introduc-tion to pyFAI, what it is, what it aims at and how it works (from the scientists point of view). Especially, geometry,calibration, azimuthal integration algorithms are described and pixel splitting schemes are explained.
Follows cookbook and tutorials on how to use pyFAI: Cookbooks focus on how to use pyFAI using the variousgraphical interfaces or from scripts on the command linee. Tutorials use the Jupyter notebook (formerly ipython)and present the Python interface. The first tutorial start with a quick general introduction of the notebooks, howto process data in the general case, subsequent tutorials are more advanced and require already a good knowledgeboth in Python and pyFAI.. After the tutorials, all manual pages of pyFAI programs, both graphical interfaces andscripts are described in the documentation.
The design of the programming interface (API) is then exposed before a comprehensive description of mostmodules contained in pyFAI. Some minor submodules as well as the documentation of the Cython sub-modulesare not included for concision purposes.
Installation procedures for Windows, MacOSX and Linux operating systems are then described.
Finally other programs/projects relying on pyFAI are presented and the project is summarized from a developer’spoint of view.
In appendix there are some figures about the project and its management and a list of publication on pyFAI.
Contents 1
![Page 6: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/6.jpg)
pyFAI Documentation, Release 0.15.0a0
2 Contents
![Page 7: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/7.jpg)
CHAPTER 1
General introduction to PyFAI
Python Fast Azimuthal Integration
PyFAI is implemented in Python programming language, which is open source and already very popular forscientific data analysis ([PyMca], [PyNX], . . . ). It relies on the scientific stack of python composed of [NumPy],[SciPy] and [Matplotlib] plus the [OpenCL] binding [PyOpenCL] for performances.
2𝐷 area detectors like CCD or pixel detectors have become popular in the last 15 years for diffraction exper-iments (e.g. for WAXS, SAXS, single crystal and powder diffraction). These detectors have a large sensitivearea of millions of pixels with high spatial resolution. The software package pyFAI ([SRI2012], [EPDIC13]) hasbeen designed to reduce SAXS, WAXS and XRPD images taken with those detectors into 1𝐷 curves (azimuthalintegration) usable by other software for in-depth analysis such as Rietveld refinement, or 2𝐷 images (a radialtransformation named caking in [FIT2D]). As a library, the aim of pyFAI is to be integrated into other tools like[PyMca] or [EDNA] or [LImA] with a clean pythonic interface. However pyFAI features also command line andgraphical tools for batch processing, converting data into q-space (q being the momentum transfer) or 2𝜃-space (𝜃being the Bragg angle) and a calibration graphical interface for optimizing the geometry of the experiment usingthe Debye-Scherrer rings of a reference sample. PyFAI shares the geometry definition of SPD but can directlyimport geometries determined by the software FIT2D. PyFAI has been designed to work with any kind of detectorand geometry (transmission or reflection) and relies on FabIO, a library able to read more than 20 image formatsproduced by detectors from 12 different manufacturers. During the transformation from cartesian space (𝑥, 𝑦) topolar space (2𝜃, 𝜒), both local and total intensities are conserved in order to obtain accurate quantitative results.Technical details on how this integration is implemented and how it has been ported to native code and parallelizedon graphic cards are quickly presented but you can refer to this publications for further details.
Introduction
With the advent of hyperspectral experiments like diffraction tomography in the world of synchrotron radiation,existing software tools for azimuthal integration like [FIT2D] and [SPD] reached their performance limits owingto the fast data rate needed by such experiments. Even when integrated into massively parallel frameworks like[EDNA] , such stand-alone programs, due to their monolithic nature, cannot keep the pace with the data flowof new detectors. Therefore we decided to implemente from scratch a novel azimuthal integration tool which isdesigned to take advantage of modern parallel hardware features. PyFAI assumes the setup does not change duringthe experiment and tries to reuse a maximum number of data (using memoization), moreover those calculation areperformed only when needed (lazy_evaluation).
3
![Page 8: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/8.jpg)
pyFAI Documentation, Release 0.15.0a0
Experiment description
In pyFAI, the basic experiment is defined by a description of an area-detector whose position in space is definedthrough the sample position and the incident X-ray beam, and can be calibrated using Debye-Scherrer rings of areference compound.
Detector
Simple detector
Like most other diffraction processing packages, pyFAI allows the definition of 2D detectors with a constant pixelsize and recoded in S.I.. Typical pixel size are 50e-6 m (50 microns) and will be used as example in the numericalapplication.
Pixels of the detector are indexed from the origin located at the lower left corner when looking from the sample.The pixel’s center is located at half integer index:
• pixel 0 goes from position 0 m to 50e-6m and is centered at 25e-6 m.
• pixel 1 goes from position 50e-6 m to 100e-6 m and is centered at 75e-6 m
Nota: Most of the time you will need to pass the optional argument origin=”lower” to matplotlib’s imshowfunction when displaying the image to avoid confusion.
Complex detectors
The simple detector approach reaches its limits with several detector types, such as multi-module and fiber optictaper coupled detectors (most CCDs). Large area pixel detectors are often composed of smaller modules (i.e.Pilatus from Dectris, Maxipix from ESRF, ...).
By construction, such detectors exhibit gaps between modules along with pixels of various sizes within a singlemodule, hence they require specific data masks. Optically coupled detectors need also to be corrected for smallspatial displacements, often called geometric distortion. This is why detectors need more complex definitions thanjust that of a pixel size. To avoid complicated and error-prone sets of parameters, two tools have been introduced:either detector classes define programmatically detector or Nexus saved detector setup.
Detectors classes
They are used to define families of detectors. In order to take the specificities of each detector into account, pyFAIcontains about 58 detector class definitions (and 168 with aliases) which contain a mask (invalid pixels, gaps, ...)and a method to calculate the pixel positions in Cartesian coordinates. Available detectors can be printed using:
>>> import pyFAI>>> print(pyFAI.detectors.ALL_DETECTORS)
For optically coupled CCD detectors, the geometric distortion is often described by a bi-dimensional cubic splinewhich can be imported into the detector instance and be used to calculate the actual pixel position in space.
Nexus Detectors
Any detector object in pyFAI, can be saved into a HDF5 file following the NeXus convention (http://nexusformat.org). Detector objects can subsequently be restored from the disk, making complex detector definitions less error-prone. Pixels of an area detector are saved as a 4D dataset: i.e. a 2D array of vertices pointing to every corner ofeach pixel, generating an array of shape: (Ny, Nx, Nc, 3) where Nx and Ny are the dimensions of the detector, Ncis the number of corners of each pixel, usually 4, and the last entry contains the coordinates of the vertex itself(z,y,x). This kind of definitions, while relying on large description files, can address some of the most complexdetector layouts:
4 Chapter 1. General introduction to PyFAI
![Page 9: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/9.jpg)
pyFAI Documentation, Release 0.15.0a0
• hexagonal pixels (i.e. Pixirad detectors, still under development)
• curved/bent imaging plates (i.e. Rigaku, Aarhus detector)
• pixel detectors with tiled modular (i.e. Xpad detectors from ImXpad)
• semi-cylindrical pixel detectors (i.e. Pilatus12M from Dectris or CirPad from Soleil).
The detector instance can be saved as HDF5, either programmatically, either on the command line.
from pyFAI import detectorsfrelon = detectors.FReLoN("halfccd.spline")print(frelon)frelon.save("halfccd.h5")
Using the detector2nexus script to convert a complex detector definition (multiple modules, possibly in 3D) into asingle NeXus detector definition together with the mask:
detector2nexus -s halfccd.spline -o halfccd.h5
Conclusion
Detector definition in pyFAI is very versatile. Fortunately, most detectors are already described, making the usagetransparent for most users. There are a couple of Tutorials on detector definition which will help you understandingthe underlying mechanism:
• Distortion which explains how to correct images for geometric distortion
• CCD-calibration which explains how to calibrate such detectors for geometric distortion.
Geometry
PyFAI uses a 6-parameter geometry definition similar, while not rigorously identical to SPD: One distance, 2coordinates to define the point of normal incidence and 3 rotations around the main axis; these parameters aresaved in text files usually with the .poni extension. In addition, the poni-file may contain the wavelength and thedetector definition.
Image representation in Python
PyFAI takes diffraction images as 2D numpy arrays, those are usually read using the FabIO library:
import fabiodata = fabio.open("image.edf").data
But data can also be extracted from HDF5 files with h5py and displayed using matplotlib:
%pylabimshow(data, origin="lower")
Because Python is written in C language, data are stored lines by lines, this means to go from a pixel to the on itsright, one offets the position by the pixel width. To go the pixel above the current one, on needs to offset by thelength of the line. This is why, if one considers the pixel at position (x,y), its value can be retrieved by data[y,x](note the order y,x, this is not a bug!). We usually refer the x axis as the fast dimension (because pixels areadjacent) and the y axis as the slow axis (as pixel are appart from each other by a line length). More informationon how numpy array are stored can be found at here
Like most scientific packages, the origin of the image is considered to be at the lower-left corner of the imageto have the polar angle growing from 0 along the x axis to 90 deg along the y axis. This is why we pass theorigin=”lower” option to imshow (from the matplotlib library). Axis 1 and 2 on the image (like in poni1 & poni2)refer to the slow and fast dimension of the image, so usually to the y and x axis (and not the opposite)
1.3. Experiment description 5
![Page 10: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/10.jpg)
pyFAI Documentation, Release 0.15.0a0
Position of the observer
There are two (main) conventions when representing images:
• In imaging application, one can can replace the camera by the eye, the camera looks at the scene. In thisconvention, the origin is usually at the top of the image.
• In diffraction application, the observer is situated at the sample position and looks at the detector, hence onthe other side of the detector.
Because we measure (signed) angles, the origin is ideally situated at the lower left of the image. PyFAI being adiffraction application, it uses the later description. Changing the point of view behind the detector changes thesign of the azimuthal angle.
Default geometry in pyFAI
In the (most common) case of transmission diffraction setup on synchrotrons (like ESRF, Soleil, Petra3, SLS...)this makes looks like:
• Observer looking at the detector from the sample position:
• Origin at the lower left of the detector
• Axis 1 (i.e. y) being vertical, pointing upwards
• Axis 2 (i.e. x) being horizontal, pointing to the center of the storage ring
• Axis 3 (i.e. z) being horizontal, along the incident beam
Axis 3 is built in such a way to be orthogonal to the plane (1,2). Due to constraints on the origin and orientationof the azimuthal angle, chi, (1, 2, 3) is indirect orientation. This makes usually the PONI position with negativethird coordiante (at z<0).
Detector position
In pyFAI, the experiment geometry is defined by the position of the detector in space, the origin being located atthe sample position, more precisely where the X-ray beam crosses the diffractometer main axis.
With the detector being a rigid body, its position in space is described by six parameters: 3 translations and 3rotations. In pyFAI, the beam center is not directly used as it is ill-defined with highly tilted detectors. Like SPD,we use the orthogonal projection of origin on the detector surface called PONI (for Point Of Normal Incidence).For non planar detectors, the PONI is defined in the plan z=0 in detector’s coordinate system.
Poni1 and Poni2 are distances in meter (along the y and x axis of the detector), like the sample-detector distance,letting the calibration parameters be independent of the pixel size hence stable regarding the binning factor of thedetector.
In the same idea rot1, rot2 and rot3 are rotation along axis 1, 2 and 3, always expressed in radians. Rotationsapplied in the same order: rot1 then rot2 and finally rot3. Due to the axial symmetry of the Debye-Scherrercones, rot3 cannot be optimized but can be adjusted manually in some cases like if the detector is not mountedhorizontally and/or one cares about polarization correction.
When all rotations are zero, the detector is in transmission mode with the incident beam orthogonal to the detector’ssurface.
There is also a tutorial Tutorials on the geometry which explains in detail the orientations of the different rotationsused by pyFAI.
Calibration
6 Chapter 1. General introduction to PyFAI
![Page 11: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/11.jpg)
pyFAI Documentation, Release 0.15.0a0
Calibration
The determination of the geometry of the experimental setup for the diffraction pattern of a reference sampleis called calibration in pyFAI. A geometry setup is composed of a detector, the six refined parameters like thedistance and fixed parameters like the wavelength (or the energy of the beam), they are all saved together into atext files named ”.poni” (as a reference to the point of normal incidence) which is subsequently used for processingthe experiment.
The program pyFAI-calib is used for calibrating the experimental setup using a constrained least squares opti-mization on the Debye-Scherrer rings of a reference sample (𝐿𝑎𝐵6, 𝐶𝑒𝑂2, silver behenate 𝐴𝑔𝐵ℎ, . . . ) and savesthe results into a .poni file. Alternatively, geometries calibrated using Fit2D can be imported into pyFAI, includinggeometric distortions (i.e. optical-fiber tapers distortion) described as spline-files. For Fit2D compatibility, pleaserefer to the Tutorials on basic usage of pyFAI.
By storing all parameters together in a single small file, the risk of mixing two parameters is highly reduced andwe believe this helps performing better science with fewer mistakes.
While entering the geometry of the experiment in a poni-file is possible, it is easier to perform a calibration,using the Debye-Sherrer rings of a reference sample called calibrant. About 30 calibrants are provided by pyFAIlike 𝐿𝑎𝐵6, ceria 𝐶𝑒𝑂2, silicon, corrundum or silver behenate. Among other simple compound, all of the NISTStandard Reference Materials have been are tabulated and are directly available as calibrant. One can alternativelyprovide its own calibrant description files which is a simple text-file containing the largest d-spacing (in Angstrom)for a set of Miller plans. A useful reference to generate this file is the American Mineralogist database [AMD] orthe Crystallographic Open database [COD].
The calibration procedure is divided into 4 major steps:
1.3. Experiment description 7
![Page 12: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/12.jpg)
pyFAI Documentation, Release 0.15.0a0
Pre-processing of images:
The typical pre-processing consists of the averaging (or better median filtering) of darks images. Dark currentimages are then subtracted from data and corrected for flat. The pre-processing is best performed using the pyFAI-average tool, which documentation is available in the pyFAI scripts manual.
If saturated pixels exists, the are likely to be treated like peaks but their positions will be wrong. It is advised toeither mask them out or to desaturate them (pyFAI provides an option, but it is expensive in calculation time). AMask drawing tool, called pyFAI-drawmask, is installed together with pyFAI and its documentation available inthe pyFAI scripts manual.
To start the calibration the pyFAI-calib tool will need:
• an image with Debye-Sherrer rings
• the energy or the wavelength
• the calibrant name or the d-spacing file of the calibrant
• the detector description.
Peak-picking
Once started, pyFAI-calib will ask you to select rings. The Peak-picking consists in the identification of peaks andgroups of peaks belonging to same ring. It can be performed by 4 methods described hereafter.
Massif detection
This method consists in making the difference of the original image and a blurred image. Then look for a largecontiguous region of positives values, corresponding to a single group of peak. The blurring parameter can beadjusted using the “-g” option in pyFAI-calib.
Blob detection
The approach is based on difference of gaussians (DoGs) as described in the blob_detection article of wikipedia.
It consists in blurring the image by convolution with a 2D gaussian kernel and making differences between twosuccessive blurs (called Difference Of Gaussian or DoGs). In theses DoGs, keypoints are defined as the maxima inthe 3D space (y,x,size of the gaussian). After their localization, keypoints are refined by Savitzky Golay algorithmor by an interpolation at the second order which is equivalent but uses less points. At this step, if the estimation ofthe maximum is too far from the maximum, the keypoint will be considered as a fake maximum and removed.
Steepest ascent
This is very naive implementation which looks for the nearest local maximum. Subsequently a sub-pixel opti-mization is performed based on a second order expansion using the local gradient and hessian.
Monte-Carlo sampling
Series of peaks can be extracted using the Steepest Ascent on randomly selected seeds. This method can be biasedtowards an already known geometry by starting from points which are supposed to be on the ring.
8 Chapter 1. General introduction to PyFAI
![Page 13: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/13.jpg)
pyFAI Documentation, Release 0.15.0a0
Refinement of the parameters
After selecting groups of peaks, each of them is assigned to a Debye-Scherrer ring number (0-based numberingin python) and associated to a d-spacing value hence a theoretical 2theta value. A supervised least-squares re-finement, performed on the difference of peak position’s 2-theta values versus the expected ones from calibrantprovides the 6-geometry parameters fitted.
The default optimization procedure is the Sequential Least SQuares Programming implemented inscipy.optimize.slsqp. The cost function is the sum of the square of the difference between the expected and calcu-lated 2theta values for the various peaks. This sum is dependent on the number of control-points.
Validation of the calibration
Validation by an human being of the geometry is an essential step: pyFAI will overlaps to the diffraction image,the lines corresponding to the various diffraction rings expected from the calibrant. Those lines should be inpretty good agreement with the rings of the scattering image. The average error per control point (delta 2thetaerror in radian) is printed out and offers a quantitative measurement of the relative quality of the fit for similarsetups/experiment. Nevertheless its absolute value has no meaning, except the lower, the better.
Subsequently, pyFAI offers some validation options in to check the quality of the fit. some of them global, someof them limited to given rings.
PyFAI executables
PyFAI was designed to be used by scientists needing a simple and effective tool for azimuthal integration. Thereare a certain number of scripts which will help you in preprocessing images (dark current, flat-field, averaging,...), calibrating the geometry, performing the integration. Finally couple of specialized tool called diff_tomoand diff_map are available to reduce a 2D/3D-mapping experiment of 2D images into a 3D volume (𝑥, 𝑦, 2𝜃 formapping or 𝑟𝑜𝑡, 𝑡𝑟𝑎𝑛𝑠, 2𝜃 for tomography)
There are cookbooks on these scripts in Cookbook recipes and their complete manual pages are available in thepyFAI scripts manual section.
Python library
PyFAI is first and foremost a library: a tool of the scientific toolbox built around [IPython] and [NumPy] toperform data analysis either interactively or via scripts. Figure [notebook] shows an interactive session where anintegrator is created, and an image loaded and integrated before being plotted.
The Tutorials section makes heavy use of IPython notebooks, now called Jupyter notebooks to process data usingpyFAI. The first tutorial also explains a bit how Python and Jupyter works to be able to perform basic processing
1.3. Experiment description 9
![Page 14: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/14.jpg)
pyFAI Documentation, Release 0.15.0a0
efficiently with pyFAI.
Regrouping mechanism
In pyFAI, regrouping is performed using a histogram-like algorithm. Each pixel of the image is associated toits polar coordinates (2𝜃, 𝜒) or (𝑞, 𝜒), then a pair of histograms versus 2𝜃 (or 𝑞) are built, one non weighted formeasuring the number of pixels falling in each bin and another weighted by pixel intensities (after dark-currentsubtraction, and corrections for flat-field, solid-angle and polarization). The division of the weighted histogramby the number of pixels per bin gives the average signal over the given corona which provides the diffractionpattern. 2𝐷 regrouping (called caking in FIT2D) is obtained in the same way using two-dimensional histogramsover radial (2𝜃 or 𝑞) and azimuthal angles (𝜒).
Pixel splitting algorithm
Powder diffraction patterns obtained by histogramming have a major weakness where pixel statistics are low.A manifestation of this weakness becomes apparent in the 2𝐷-regrouping where most of the bins close to thebeam-stop are not populated by any pixel. In this figure, many pixels are missing in the low 2𝜃 region, due tothe arbitrary discretization of the space in pixels as intensities were assigned to each pixel center which does notreflect the physical reality of the scattering experiment.
PyFAI solves this problem by pixel splitting : in addition to the pixel position, its spatial extension is calculated andeach pixel is then split and distributed over the corresponding bins, the intensity being considered as homogeneouswithin a pixel and spread accordingly. The drawback of this is the correlation introduced between two adjacentbins. To simplify calculations, this was initially done by abstracting the pixel shape with a bounding box thatcircumscribes the pixel. In an effort to better the quality of the results this method was dropped in favoor of a fullpixel splitting scheme that actually uses the actual pixel geometry for its calculations.
10 Chapter 1. General introduction to PyFAI
![Page 15: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/15.jpg)
pyFAI Documentation, Release 0.15.0a0
Performances and migration to native code
Originally, regrouping was implemented using the histogram provided by [NumPy], then re-implemented in[Cython] with pixel splitting to achieve a four-fold speed-up. The computation time scales like O(N) with the sizeof the input image. The number of output bins shows only little influence; overall the single threaded [Cython]implementation has been stated at 30 Mpix/s (on a 3.4 GHz Intel core i7-2600).
Parallel implementation
The method based on histograms works well on a single processor but runs into problems requiring so called“atomic operations” when run in parallel. Processing pixels in the input data order causes write access conflictswhich become less efficient with the increase of number of computing units (need of atomic_operation). Thisis the main limit of the method exposed previously; especially on GPU where thousands of threads are executedsimultaneously.
To overcome this limitation; instead of looking at where input pixels GO TO in the output image, we instead lookat where the output pixels COME FROM in the input image. This transformation is called a “scatter to gather”transformation in parallel programming.
The correspondence between pixels and output bins can be stored in a look-up table (LUT) together with the pixelweight which make the integration look like a simple (if large and sparse) matrix vector product. This look-uptable size depends on whether pixels are split over multiple bins and to exploit the sparse structure, both index andweight of the pixel have to be stored. We measured that 500 Mbytes are needed to store the LUT to integrate a 16megapixels image, which fits onto a reasonable quality graphics card nowadays but can still be too large to fit onan entry-level graphics card.
By making this change we switched from a “linear read / random write” forward algorithm to a “random read/ linear write” backward algorithm which is more suitable for parallelization. As a farther improvement on thealgorithm, the use of compressed sparse row (CSR) format was introduced, to store the LUT data. This algorithm
1.4. Regrouping mechanism 11
![Page 16: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/16.jpg)
pyFAI Documentation, Release 0.15.0a0
was implemented both in [Cython]-OpenMP and OpenCL. The CSR approach has a double benefit: first, it reducesthe size of the storage needed compared to the LUT by a factor two to three, offering the opportunity of workingwith larger images on the same hardware. Secondly, the CSR implementation in OpenCL is using an algorithmbased on multiple parallel reductions where many execution threads are collaborating to calculate the content ofa single bin. This makes it very well suited to run on GPUs and accelerators where hundreds to thousands ofsimultaneous threads are available.
When using OpenCL for the GPU we used a compensated (or Kahan_summation), to reduce the error accumu-lation in the histogram summation (at the cost of more operations to be done). This allows accurate results tobe obtained on cheap hardware that performs calculations in single precision floating-point arithmetic (32 bits)which are available on consumer grade graphic cards. Double precision operations are currently limited to highprice and performance computing dedicated GPUs. The additional cost of Kahan summation, 4x more arithmeticoperations, is hidden by smaller data types, the higher number of single precision units and that the GPU is usuallylimited by the memory bandwidth anyway.
The performances of the parallel implementation based on a LUT, stored in CSR format, can reach 2.5 GPix/s onrecent multi-core computer with a gaming graphics card. On multi-socket server featuring high-end GPUs likeTesla cards, the performances are similar with the additional capability to work on multiple detector simultane-ously.
Related Work
There are many projects which are already relying on pyFAI: Dioptas, NanoPeakCell, Dpdak, PySAXS, xPDF-Suite ... There is a list of Program using pyFAI as a library on the ecosystem page.
Conclusion
The library pyFAI was developed with two main goals:
• Performing azimuthal integration with a clean programming interface.
• No compromise on the quality of the results is accepted: a careful management of the geometry and precisepixel splitting ensures total and local intensity preservation.
12 Chapter 1. General introduction to PyFAI
![Page 17: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/17.jpg)
pyFAI Documentation, Release 0.15.0a0
PyFAI is the first implementation of an azimuthal integration algorithm on a GPUs as far as we are aware of, andthe stated twenty-fold speed up opens the door to a new kind of analysis, not even considered before. With agood interface close to the camera, we believe PyFAI is able to sustain the data streams from the next generationhigh-speed detectors.
Acknowledgments
Porting pyFAI to GPU would have not been possible without the financial support of LinkSCEEM-2 (RI-261600).
1.6. Conclusion 13
![Page 18: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/18.jpg)
pyFAI Documentation, Release 0.15.0a0
14 Chapter 1. General introduction to PyFAI
![Page 19: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/19.jpg)
CHAPTER 2
Cookbook recipes
Cookbook are short tutorials: 1 page, 5 minutes to read.
Calibration of a diffraction setup
The files needed for this cookbook can be downloaded on: http://www.silx.org/pub/pyFAI/cookbook/calibration/You can download them to practice:
$ mkdir calibration$ cd calibration$ wget http://www.silx.org/pub/pyFAI/cookbook/calibration/LaB6_29.4keV.tif$ wget http://www.silx.org/pub/pyFAI/cookbook/calibration/F_K4320T_Cam43_30012013_→˓distorsion.spline$ lsF_K4320T_Cam43_30012013_distorsion.spline LaB6_29.4keV.tif
The associated video is here
Review your calibration image
As viewer, try fabio_viewer from the FabIO package
$ fabio_viewer LaB6_29.4keV.tif
You may need to pre-process your data, pyFAI-average is a tool to perform pixel-wise transformation. In thisexample, the image file was obtained using a “max filter” over 20 frames with pyFAI-average:
$ pyFAI-average -m max -F tif -o LaB6_29.4keV.tif ref_lab6_00??.edf
Get all additional data
• calibrant used: LaB6 according to the name of the file
• the energy or the wavelength, 29.4keV according to the name of the file
• detector geometry: there is a spline file along with the file
15
![Page 20: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/20.jpg)
pyFAI Documentation, Release 0.15.0a0
16 Chapter 2. Cookbook recipes
![Page 21: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/21.jpg)
pyFAI Documentation, Release 0.15.0a0
• masks, dark, flat ... are not going to be used to keep things simple.
Start pyFAI-calib
Use the man page (or –help) to see all options, or go to the pyFAI scripts manual section.
Here we just provide the energy, the detector disortion file and the calibrant options in addition to the image file.
$ pyFAI-calib -e 29.4 -s F_K4320T_Cam43_30012013_distorsion.spline -c LaB6 LaB6_29.→˓4keV.tifFixedParameters(['wavelength'])ERROR:pyFAI.peak_picker:ControlPoint.load: No such file LaB6_29.4keV.nptINFO:pyFAI.massif:Image size is (2048, 2048)INFO:pyFAI.massif:Binning size is [2, 2]INFO:pyFAI.massif:Labeling found 7272 massifs.INFO:pyFAI.massif:Labeling found 7272 massifs.INFO:root:Please select rings on the diffraction image. In parenthesis, some→˓modified shortcuts for single button mouse (Apple):
* Right-click (click+n): try an auto find for a ring
* Right-click + Ctrl (click+b): create new group with one point
* Right-click + Shift (click+v): add one point to current group
* Right-click + m (click+m): find more points for current group
* Center-click or (click+d): erase current group
* Center-click + 1 or (click+1): erase closest point from current groupPlease press enter when you are happy with your selection
Pick peaks
To perform the calibration one needs to create control points and assign them to rings.
• Right click on a few (5) points in the inner-most ring which has the index number #0
• Increase the counter on the top right to change the ring number and pick a few more points on the corre-sponding ring (again with right click).
Review the group of peaks
Press Enter in the terminal to do so... and check the ring assignment
Once done with all groups, the position of the expected rings is overlaid to the diffraction image. You may needto unzoom to view them !
Now fill in the ring number. Ring number starts at 0, like point-groups.Point group # a (4 points) (1315.9,1090.1) [default=0] Ring#Point group # b (5 points) (1302.0, 926.0) [default=0] Ring#Point group # c (2 points) (1085.3,1268.1) [default=0] Ring#Point group # d (2 points) ( 850.1,1083.3) [default=0] Ring#Point group # e (5 points) ( 965.1, 825.7) [default=0] Ring#Point group # f (4 points) ( 898.2,1315.9) [default=1] Ring#Point group # g (2 points) (1244.6, 733.6) [default=1] Ring#Point group # h (2 points) (1350.1, 821.9) [default=1] Ring#Optimization terminated successfully. (Exit mode 0)
Acquire some more control points
• Use recalib to extract a new set of control points, specify the number of rings, first a few of them then more
• You may want to free/fix/bound some parameter then refine again
2.1. Calibration of a diffraction setup 17
![Page 22: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/22.jpg)
pyFAI Documentation, Release 0.15.0a0
18 Chapter 2. Cookbook recipes
![Page 23: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/23.jpg)
pyFAI Documentation, Release 0.15.0a0
2.1. Calibration of a diffraction setup 19
![Page 24: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/24.jpg)
pyFAI Documentation, Release 0.15.0a0
Fixed: wavelengthModify parameters (or ? for help)? recalib 6[...]Fixed: wavelengthModify parameters (or ? for help)? recalib 15[...]Fixed: wavelengthModify parameters (or ? for help)? recalib 25
Visualize the integrated patterns
• integrate to view the integrated pattern
• then extract a few extra rings ...
• the geometry is displayed on the screen, and saved automatically in the poni-file
Fixed: wavelengthModify parameters (or ? for help)? integrate
20 Chapter 2. Cookbook recipes
![Page 25: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/25.jpg)
pyFAI Documentation, Release 0.15.0a0
2.1. Calibration of a diffraction setup 21
![Page 26: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/26.jpg)
pyFAI Documentation, Release 0.15.0a0
Quit
Fixed: wavelengthModify parameters (or ? for help)? quit$
lsF_K4320T_Cam43_30012013_distorsion.spline LaB6_29.4keV.npt LaB6_29.4keV.tifLaB6_29.4keV.azim LaB6_29.4keV.poni LaB6_29.4keV.xy
All different geometries have been saved into the LaB6_29.4keV.poni file and can directly be used with pyFAI-integrate. All control points are saved into LaB6_29.4keV.npt.
Final notes: In this case the calibration is far from being good and it is likely the distortion file applied is not theproper one according to many the waves on the 2D integration pattern. If one flips up-down the spline file priorto the calibration, the residual error is twice lower but the goes far beyond this cookbook. Here is the diffractionpattern from a properly calibrated setup:
from pyFAI.spline import Splines = Spline("F_K4320T_Cam43_30012013_distorsion.spline")ud = s.flipud()ud.write("flipud.spline")
Azimuthal integration using the graphical user interface
Associated video
Look at your integrated patterns
PyFAI can perform 1D or 2D integration. To view 1D patterns, I will use grace Let’s look at the integrated patternsobtained during calibration.
As you can see, only the 10 rings used for calibration are well defined.
22 Chapter 2. Cookbook recipes
![Page 27: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/27.jpg)
pyFAI Documentation, Release 0.15.0a0
This file is a text file containing as header all metadata needed to determine the geometry.
2D integrated pattern (aka cake images) are EDF images. Try fabio_viewer to see them.
Once again check the header of the file and the associated metadata.
Integrate a bunch of images
We will work with the 20 images used for the calibration.
Start pyFAI-intgrate
Either select files to process using the file-dialog or provide them on the command line.
Set the geometry
Simply load the PONI file and check the populated fields.
Azimuthal integration options
Check the dark/flat/ ... options Use the check-box to activate the option.
Do NOT forget to specify the number of radial bins !
Select the device for processing
Unless the processing will be done on the CPU using OpenMP.
Press OK to start the processing.
The generation of the Look-Up table takes a few seconds then all files get processed quickly
Run it again to perform caking
Same a previously ... but provide a number of azimuthal bins !
Visualize the integrated patterns
Once again I used grace and fabio_viewer to display the result.
That’s all.
Azimuthal integration using scripts
Azimuthal integration using Python
This cookbook is now available a a tutorial using jupyter on the Tutorials section.
For more in depth explanation, see the Tutorials section.
2.3. Azimuthal integration using scripts 23
![Page 28: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/28.jpg)
pyFAI Documentation, Release 0.15.0a0
24 Chapter 2. Cookbook recipes
![Page 29: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/29.jpg)
CHAPTER 3
Tutorials
Tutorials explain the Python interface of pyFAI and use the jupyter notebook interface, formerly known as ipythonnotebooks. The two first tutorials are an introduction to the usage of pyFAI from Python for diffraction datareduction. The subsequent tutorials are more in depth explanation and require a good Python fluency and to acertain extent, of the pyFAI library.
Introduction to the tutorials
The iPython/Jupyter notebook
The document you are seeing it may be a PDF or a web page or another format, but what is important is how ithas been made ...
According to this article in Nature the Notebook, invented by iPython, and now part of the Jupyter project, is therevolution for data analysis which will allow reproducable science.
This tutorial will introduce you to how to access to the notebook, how to use it and perform some basic dataanalysis with it and the pyFAI library.
Getting access to the notebook
There are many cases ...
Inside ESRF
The simplest case as the data analysis unit offers you a notebook server: just connect your web browser to http://scisoft13:8000 and authenticate with your ESRF credentials.
Outside ESRF with an ESRF account.
The JupyterHub server is not directly available on the internet, but you can login into the firewall to forward theweb server:
ssh -XC -p5022 -L8000:scisoft13:8000 [email protected]
25
![Page 30: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/30.jpg)
pyFAI Documentation, Release 0.15.0a0
Once logged in ESRF, keep the terminal opened and browse on your local computer to http://localhost:8000 toauthenticate with your ESRF credentials. Do not worry about confidentiality as the connection from your computerto the ESRF firewall is encrypted by the SSH connection.
Other cases
In the most general case you will need to install the notebook on your local computer in addition to silx, pyFAIand FabIO to follow the tutorial. WinPython provides it under windows. Please refer to the installation procedureof pyFAI to install locally pyFAI on your computer. Anaconda provides also pyFAI and FabIO as packages.
Getting trained in using the notebook
There are plenty of good tutorials on how to use the notebook. This one presents a quick overview of the Pythonprogramming language and explains how to use the notebook. Reading it is strongly encouraged before proceedingto the pyFAI itself.
Anyway, the most important information is to use Control-Enter to evaluate a cell.
In addition to this, we will need to download some files from the internet. The following cell contains a piece ofcode to download files using the silx library. You may have to adjust the proxy settings to be able to connect tointernet, especially at ESRF, see the commented out code.
Introduction to diffraction image analysis using the notebook
All the tutorials in pyFAI are based on the notebook and if you wish to practice the exercises, you can downloadthe notebook files (.ipynb) from Github
Load and display diffraction images
First of all we will download an image and display it. Displaying it the right way is important as the orientationof the image imposes the azimuthal angle sign.
#For inside ESRF: this sets up the proxy settings:import os, timeos.environ["http_proxy"] = "http://proxy.esrf.fr:3128"start_time = time.time()
from silx.resources import ExternalResourcesdownloader = ExternalResources("pyFAI", "http://www.silx.org/pub/pyFAI/testimages/→˓", "DATA")
moke = downloader.getfile("moke.tif")print(moke)
/tmp/pyFAI_testdata_kieffer/moke.tif
The moke.tif image we just downloaded is not a real diffraction image but it is a test pattern used in the tests ofpyFAI.
Prior to displaying it, we will use the Fable Input/Output library to read the content of the file:
#initializes the visualization module to work with the jupyter notebook%pylab nbagg
Populating the interactive namespace from numpy and matplotlib
26 Chapter 3. Tutorials
![Page 31: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/31.jpg)
pyFAI Documentation, Release 0.15.0a0
import fabiofrom pyFAI.gui import jupyterimg = fabio.open(moke).datajupyter.display(img, label ="Fake diffraction image")
<IPython.core.display.Javascript object>
<matplotlib.axes._subplots.AxesSubplot at 0x7fe014040ba8>
As you can see, the image looks like an archery target. The origin is at the lower left of the image. If you arefamiliar with matplotlib, it correspond to the option origin=”lower” of imshow.
Displaying the image using imsho without this option ends with having the azimuthal angle (which angles aredisplayed in degrees on the image) to turn clockwise, so the inverse of the trigonometric order:
fig, ax = subplots(1,2, figsize=(10,5))ax[0].imshow(img, origin="lower")ax[0].set_title("Proper orientation")ax[1].imshow(img)ax[1].set_title("Wrong orientation")
<IPython.core.display.Javascript object>
<matplotlib.text.Text at 0x7fdfca7cecc0>
Nota: Displaying the image properly or not does not change the content of the image nor its representation inmemory, it only changes its representation, which is important only for the user. DO NOT USE numpy.flipud orother array-manipulation which changes the memory representation of the image. This is likely to mess-up allyour subsequent calculation.
1D azimuthal integration
To perform an azimuthal integration of this image, we need to create an AzimuthalIntegrator object we will callai. Fortunately, the geometry is explained on the image.
import pyFAIdetector = pyFAI.detectors.Detector(pixel1=1e-4, pixel2=1e-4)ai = pyFAI.AzimuthalIntegrator(dist=0.1, detector=detector)# Short version ai = pyFAI.AzimuthalIntegrator(dist=0.1, pixel1=1e-4, pixel2=1e-4)print(ai)
Detector Detector Spline= None PixelSize= 1.000e-04, 1.000e-04 mSampleDetDist= 1.000000e-01m PONI= 0.000000e+00, 0.000000e+00m rot1=0.→˓000000 rot2= 0.000000 rot3= 0.000000 radDirectBeamDist= 100.000mm Center: x=0.000, y=0.000 pix Tilt=0.000 deg→˓tiltPlanRotation= 0.000 deg
Printing the ai object displays 3 lines:
• The detector definition, here a simple detector with square, regular pixels with the right size
• The detector position in space using the pyFAI coordinate system: dist, poni1, poni2, rot1, rot2, rot3
• The detector position in space using the FIT2D coordinate system: direct_sample_detector_distance, cen-ter_X, center_Y, tilt and tilt_plan_rotation
Right now, the geometry in the ai object is wrong. It may be easier to define it correctly using the FIT2D geometrywhich uses pixels for the center coordinates (but the sample-detector distance is in millimeters).
3.1. Introduction to the tutorials 27
![Page 32: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/32.jpg)
pyFAI Documentation, Release 0.15.0a0
help(ai.setFit2D)
Help on method setFit2D in module pyFAI.geometry:
setFit2D(directDist, centerX, centerY, tilt=0.0, tiltPlanRotation=0.0, pixelX=None,→˓ pixelY=None, splineFile=None) method of pyFAI.azimuthalIntegrator.→˓AzimuthalIntegrator instance
Set the Fit2D-like parameter set: For geometry description seeHPR 1996 (14) pp-240
Warning: Fit2D flips automatically images depending on their file-format.By reverse engineering we noticed this behavour for Tiff and Mar345 images (at
→˓least).To obtaine correct result you will have to flip images using numpy.flipud.
:param direct: direct distance from sample to detector along the incident beam→˓(in millimeter as in fit2d)
:param tilt: tilt in degrees:param tiltPlanRotation: Rotation (in degrees) of the tilt plan arround the Z-
→˓detector axis
* 0deg -> Y does not move, +X goes to Z<0
* 90deg -> X does not move, +Y goes to Z<0
* 180deg -> Y does not move, +X goes to Z>0
* 270deg -> X does not move, +Y goes to Z>0
:param pixelX,pixelY: as in fit2d they ar given in micron, not in meter:param centerX, centerY: pixel position of the beam center:param splineFile: name of the file containing the spline
ai.setFit2D(100, 300, 300)print(ai)
Detector Detector Spline= None PixelSize= 1.000e-04, 1.000e-04 mSampleDetDist= 1.000000e-01m PONI= 3.000000e-02, 3.000000e-02m rot1=0.→˓000000 rot2= 0.000000 rot3= 0.000000 radDirectBeamDist= 100.000mm Center: x=300.000, y=300.000 pix Tilt=0.000 deg→˓ tiltPlanRotation= 0.000 deg
With the ai object properly setup, we can perform the azimuthal integration using the intergate1d method. Thismethods takes only 2 mandatory parameters: the image to integrate and the number of bins. We will provide a fewother to enforce the calculations to be performed in 2theta-space and in degrees:
res = ai.integrate1d(img, 300, unit="2th_deg")
#Display the integration resultfig, ax = subplots(1,2, figsize=(10,5))jupyter.plot1d(res, label="moke",ax=ax[0])
#Example using pure matplotlibtth = res[0]I = res[1]ax[1].plot(tth, I, label="moke")ax[1].set_title("Display 1d powder diffraction data using pure matplotlib")
<IPython.core.display.Javascript object>
<matplotlib.text.Text at 0x7fdfca6f7898>
As you can see, the 9 rings gave 9 sharp peaks at 2theta position regularly ranging from 4 to 12 degrees as expectedfrom the image annotation.
28 Chapter 3. Tutorials
![Page 33: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/33.jpg)
pyFAI Documentation, Release 0.15.0a0
Nota: the default radial unit is “q_nm^1”, so the scattering vector length expressed in inverse nanometers. Tobe able to calculate q, one needs to specify the wavelength used (here we didn’t). For example: ai.wavelength =1e-10
To save the content of the integrated pattern into a 2 column ASCII file, one can either save the (tth, I) arrays, ordirectly ask pyFAI to do it by providing an output filename:
ai.integrate1d(img, 30, unit="2th_deg", filename="moke.dat")
# now display the content of the filewith open("moke.dat") as fd:
for line in fd:print(line.strip())
# == pyFAI calibration ==# SplineFile: None# PixelSize: 1.000e-04, 1.000e-04 m# PONI: 3.000e-02, 3.000e-02 m# Distance Sample to Detector: 0.1 m# Rotations: 0.000000 0.000000 0.000000 rad## == Fit2d calibration ==# Distance Sample-beamCenter: 100.000 mm# Center: x=300.000, y=300.000 pix# Tilt: 0.000 deg TiltPlanRot: 0.000 deg## Polarization factor: None# Normalization factor: 1.0# --> moke.dat# 2th_deg I3.831631e-01 6.384597e+001.149489e+00 1.240657e+011.915815e+00 1.222277e+012.682141e+00 1.170348e+013.448468e+00 9.964798e+004.214794e+00 8.913503e+004.981120e+00 9.104074e+005.747446e+00 9.242975e+006.513772e+00 6.136262e+007.280098e+00 9.039030e+008.046424e+00 9.203415e+008.812750e+00 9.324570e+009.579076e+00 6.470130e+001.034540e+01 7.790757e+001.111173e+01 9.410036e+001.187805e+01 9.464832e+001.264438e+01 7.749060e+001.341071e+01 1.151200e+011.417703e+01 1.324891e+011.494336e+01 1.038730e+011.570969e+01 1.069764e+011.647601e+01 1.056094e+011.724234e+01 1.286720e+011.800866e+01 1.323239e+011.877499e+01 1.548398e+011.954132e+01 2.364553e+012.030764e+01 2.537154e+012.107397e+01 2.512984e+012.184029e+01 2.191267e+012.260662e+01 7.605135e+00
This “moke.dat” file contains in addition to the 2th/I value, a header commented with “#” with the geometry usedto perform the calculation.
3.1. Introduction to the tutorials 29
![Page 34: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/34.jpg)
pyFAI Documentation, Release 0.15.0a0
**Nota: ** The ai object has initialized the geometry on the first call and re-uses it on subsequent calls. This iswhy it is important to re-use the geometry in performance critical applications.
2D integration or Caking
One can perform the 2D integration which is called caking in FIT2D by simply calling the intrgate2d method with3 mandatroy parameters: the data to integrate, the number of radial bins and the number of azimuthal bins.
res2d = ai.integrate2d(img, 300, 360, unit="2th_deg")
#Display the integration resultfig, ax = subplots(1,2, figsize=(10,5))jupyter.plot2d(res2d, label="moke",ax=ax[0])
#Example using pure matplotlibI, tth, chi = res2dax[1].imshow(I, origin="lower", extent=[tth.min(), tth.max(), chi.min(), chi.→˓max()], aspect="auto")ax[1].set_xlabel("2 theta (deg)")ax[1].set_ylabel("Azimuthal angle chi (deg)")
<IPython.core.display.Javascript object>
<matplotlib.text.Text at 0x7fdfca6930b8>
The displayed images the “caked” image with the radial and azimuthal angles properly set on the axes. Search forthe -180, -90, 360/0 and 180 mark on the transformed image.
Like integrate1d, integrate2d offers the ability to save the intgrated image into an image file (EDF format bydefault) with again all metadata in the headers.
Radial integration
Radial integration can directly be obtained from Caked images:
target = 8 #degrees#work on fewer radial bins in order to have an actual averaging:I, tth, chi = ai.integrate2d(img, 100, 90, unit="2th_deg")column = argmin(abs(tth-target))print("Column number %s"%column)
fig, ax = subplots()ax.plot(chi, I[:,column], label=r"$2\theta=%.1f^{o}$"%target)ax.set_xlabel("Azimuthal angle")ax.set_ylabel("Intensity")ax.set_title("Radial intgration")ax.legend()
Column number 34
<IPython.core.display.Javascript object>
<matplotlib.legend.Legend at 0x7fdfca61d668>
Nota: the pattern with higher noise along the diagonals is typical from the pixel splitting scheme employed.Here this scheme is a “bounding box” which makes digonal pixels look a bit larger (+40%) than the ones on thehorizontal and vertical axis, explaining the variation of the noise.
30 Chapter 3. Tutorials
![Page 35: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/35.jpg)
pyFAI Documentation, Release 0.15.0a0
Integration of a bunch of files using pyFAI
Once the processing for one file is established, one can loop over a bunch of files. A convienient way to get thelist of files matching a pattern is with the glob module.
Most of the time, the azimuthal integrator is obtained by simply loading the poni-file into pyFAI and use it directly.
all_files = downloader.getdir("alumina.tar.bz2")all_edf = [i for i in all_files if i.endswith("edf")]all_edf.sort()print("Number of EDF downloaded: %s"%len(all_edf))
Number of EDF downloaded: 52
ponifile = [i for i in all_files if i.endswith(".poni")][0]splinefile = [i for i in all_files if i.endswith(".spline")][0]print(ponifile, splinefile)ai = pyFAI.load(ponifile)ai.detector.splineFile = splinefileprint(ai)
/tmp/pyFAI_testdata_kieffer/alumina/al2o3_00_max_51_frames.poni /tmp/pyFAI_→˓testdata_kieffer/alumina/distorsion_2x2.splineDetector Detector Spline= /tmp/pyFAI_testdata_kieffer/alumina/distorsion_2x2.→˓spline PixelSize= 1.034e-04, 1.025e-04 mWavelength= 7.084811e-11mSampleDetDist= 1.168599e-01m PONI= 5.295653e-02, 5.473342e-02m rot1=0.→˓015821 rot2= 0.009404 rot3= 0.000000 radDirectBeamDist= 116.880mm Center: x=515.795, y=522.995 pix Tilt=1.055 deg→˓ tiltPlanRotation= 149.271 deg
fig, ax = subplots()
for one_file in all_edf:destination = os.path.splitext(one_file)[0]+".dat"image = fabio.open(one_file).datat0 = time.time()res = ai.integrate1d(image, 1000, filename=destination)print("%s: %.3fs"%(destination, time.time()-t0))jupyter.plot1d(res, ax=ax)
<IPython.core.display.Javascript object>
/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0000.dat: 0.961s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0001.dat: 0.016s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0002.dat: 0.016s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0003.dat: 0.021s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0004.dat: 0.022s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0005.dat: 0.014s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0006.dat: 0.015s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0007.dat: 0.019s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0008.dat: 0.014s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0009.dat: 0.021s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0010.dat: 0.022s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0011.dat: 0.019s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0012.dat: 0.014s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0013.dat: 0.015s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0014.dat: 0.015s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0015.dat: 0.014s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0016.dat: 0.014s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0017.dat: 0.028s
3.1. Introduction to the tutorials 31
![Page 36: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/36.jpg)
pyFAI Documentation, Release 0.15.0a0
/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0018.dat: 0.024s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0019.dat: 0.017s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0020.dat: 0.015s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0021.dat: 0.014s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0022.dat: 0.015s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0023.dat: 0.015s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0024.dat: 0.018s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0025.dat: 0.032s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0026.dat: 0.031s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0027.dat: 0.026s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0028.dat: 0.017s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0029.dat: 0.016s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0030.dat: 0.015s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0031.dat: 0.016s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0032.dat: 0.022s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0033.dat: 0.032s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0034.dat: 0.033s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0035.dat: 0.025s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0036.dat: 0.021s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0037.dat: 0.029s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0038.dat: 0.030s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0039.dat: 0.023s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0040.dat: 0.030s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0041.dat: 0.027s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0042.dat: 0.018s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0043.dat: 0.015s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0044.dat: 0.014s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0045.dat: 0.015s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0046.dat: 0.016s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0047.dat: 0.015s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0048.dat: 0.013s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0049.dat: 0.015s/tmp/pyFAI_testdata_kieffer/alumina/al2o3_0050.dat: 0.015s/tmp/pyFAI_testdata_kieffer/alumina/dark_0001.dat: 0.025s
This was a simple integration of 50 files, saving the result into 2 column ASCII files.
Nota: the first frame took 40x longer than the other. This highlights go crucial it is to re-use azimuthal intgratorobjects when performance matters.
Conclusion
Using the notebook is rather simple as it allows to mix comments, code, and images for visualization of scientificdata.
The basic use pyFAI’s AzimuthalIntgrator has also been presented and may be adapted to you specific needs.
print("Total execution time: %.3fs"%(time.time()-start_time))
Total execution time: 11.491s
Geometries in pyFAI
This notebook demonstrates the different orientations of axes in the geometry used by pyFAI.
Demonstration
The tutorial uses the Jypyter notebook.
32 Chapter 3. Tutorials
![Page 37: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/37.jpg)
pyFAI Documentation, Release 0.15.0a0
import timestart_time = time.time()%pylab nbagg
Populating the interactive namespace from numpy and matplotlib
import pyFAIfrom pyFAI.gui import jupyterfrom pyFAI.calibrant import get_calibrant
We will use a fake detector of 1000x1000 pixels of 100_µm each. The simulated beam has a wavelength of0.1_nm and the calibrant chose is silver behenate which gives regularly spaced rings. The detector will originallybe placed at 1_m from the sample.
wl = 1e-10cal = get_calibrant("AgBh")cal.wavelength=wl
detector = pyFAI.detectors.Detector(100e-6, 100e-6)detector.max_shape=(1000,1000)
ai = pyFAI.AzimuthalIntegrator(dist=1, detector=detector)ai.wavelength = wl
img = cal.fake_calibration_image(ai)jupyter.display(img, label="Inital")
<IPython.core.display.Javascript object>
<matplotlib.axes._subplots.AxesSubplot at 0x7f20162011d0>
Translation orthogonal to the beam: poni1 and poni2
We will now set the first dimension (vertical) offset to the center of the detector: 100e-6 * 1000 / 2
p1 = 100e-6 * 1000 / 2print("poni1:", p1)ai.poni1 = p1img = cal.fake_calibration_image(ai)jupyter.display(img, label="set poni1")
poni1: 0.05
<IPython.core.display.Javascript object>
<matplotlib.axes._subplots.AxesSubplot at 0x7f201616e828>
Let’s do the same in the second dimensions: along the horizontal axis
p2 = 100e-6 * 1000 / 2print("poni2:", p2)ai.poni2 = p2print(ai)img = cal.fake_calibration_image(ai)jupyter.display(img, label="set poni2")
3.2. Geometries in pyFAI 33
![Page 38: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/38.jpg)
pyFAI Documentation, Release 0.15.0a0
poni2: 0.05Detector Detector Spline= None PixelSize= 1.000e-04, 1.000e-04 mWavelength= 1.000000e-10mSampleDetDist= 1.000000e+00m PONI= 5.000000e-02, 5.000000e-02m rot1=0.→˓000000 rot2= 0.000000 rot3= 0.000000 radDirectBeamDist= 1000.000mm Center: x=500.000, y=500.000 pix Tilt=0.000 deg→˓ tiltPlanRotation= 0.000 deg
<IPython.core.display.Javascript object>
<matplotlib.axes._subplots.AxesSubplot at 0x7f20161461d0>
The image is now properly centered. Let’s investigate the sample-detector distance dimension.
For this we need to describe a detector which has a third dimension which will be offseted in the third dimensionby half a meter.
#define 3 plotsfig, ax = subplots(1, 3, figsize=(12,4))
import copyref_10 = cal.fake_calibration_image(ai, W=1e-4)jupyter.display(ref_10, label="dist=1.0m", ax=ax[1])
ai05 = copy.copy(ai)ai05.dist = 0.5ref_05 = cal.fake_calibration_image(ai05, W=1e-4)jupyter.display(ref_05, label="dist=0.5m", ax=ax[0])
ai15 = copy.copy(ai)ai15.dist = 1.5ref_15 = cal.fake_calibration_image(ai15, W=1e-4)jupyter.display(ref_15, label="dist=1.5m", ax=ax[2])
<IPython.core.display.Javascript object>
<matplotlib.axes._subplots.AxesSubplot at 0x7f2016026358>
We test now if the sensot of the detector is not located at Z=0 in the detector referential but any arbitrary value:
class ShiftedDetector(pyFAI.detectors.Detector):IS_FLAT = False # this detector is flatIS_CONTIGUOUS = True # No gaps: all pixels are adjacents, speeds-up
→˓calculationAPI_VERSION = "1.0"aliases = ["ShiftedDetector"]MAX_SHAPE=1000,1000def __init__(self, pixel1=100e-6, pixel2=100e-6, offset=0):
pyFAI.detectors.Detector.__init__(self, pixel1=pixel1, pixel2=pixel2)self.d3_offset = offset
def calc_cartesian_positions(self, d1=None, d2=None, center=True, use_→˓cython=True):
res = pyFAI.detectors.Detector.calc_cartesian_positions(self, d1=d1, d2=d2,→˓ center=center, use_cython=use_cython)
return res[0], res[1], numpy.ones_like(res[1])*self.d3_offset
#This creates a detector offseted by half a meter !shiftdet = ShiftedDetector(offset=0.5)print(shiftdet)
34 Chapter 3. Tutorials
![Page 39: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/39.jpg)
pyFAI Documentation, Release 0.15.0a0
Detector ShiftedDetector Spline= None PixelSize= 1.000e-04, 1.000e-04 m
aish = pyFAI.AzimuthalIntegrator(dist=1, poni1=p1, poni2=p2, detector=shiftdet,→˓wavelength=wl)print(aish)shifted = cal.fake_calibration_image(aish, W=1e-4)jupyter.display(shifted, label="dist=1.0m, offset Z=+0.5m")
Detector ShiftedDetector Spline= None PixelSize= 1.000e-04, 1.000e-04 mWavelength= 1.000000e-10mSampleDetDist= 1.000000e+00m PONI= 5.000000e-02, 5.000000e-02m rot1=0.→˓000000 rot2= 0.000000 rot3= 0.000000 radDirectBeamDist= 1000.000mm Center: x=500.000, y=500.000 pix Tilt=0.000 deg→˓ tiltPlanRotation= 0.000 deg
<IPython.core.display.Javascript object>
<matplotlib.axes._subplots.AxesSubplot at 0x7f20161e2a90>
This image is the same as the one with dist=1.5m The positive distance along the d3 direction is equivalent toincrease the distance. d3 is in the same direction as the incoming beam.
After investigation of the three translations, we will now investigate the rotation along the different axes.
Investigation on the rotations:
Any rotations of the detector apply after the 3 translations (dist, poni1 and poni2)
The first axis is the vertical one and a rotation around it ellongates ellipses along the orthogonal axis:
rotation = +0.2ai.rot1 = rotationprint(ai)img = cal.fake_calibration_image(ai)jupyter.display(img, label="rot1 = 0.2 rad")
Detector Detector Spline= None PixelSize= 1.000e-04, 1.000e-04 mWavelength= 1.000000e-10mSampleDetDist= 1.000000e+00m PONI= 5.000000e-02, 5.000000e-02m rot1=0.→˓200000 rot2= 0.000000 rot3= 0.000000 radDirectBeamDist= 1020.339mm Center: x=-1527.100, y=500.000 pix Tilt=11.459→˓deg tiltPlanRotation= 180.000 deg
<IPython.core.display.Javascript object>
<matplotlib.axes._subplots.AxesSubplot at 0x7f2015f5a588>
So a positive rot1 is equivalent to turning the detector to the right, around the sample position (where the observeris).
Let’s consider now the rotation along the horizontal axis, rot2:
rotation = +0.2ai.rot1 = 0ai.rot2 = rotationprint(ai)img = cal.fake_calibration_image(ai)
jupyter.display(img, label="rot2 = 0.2 rad")
3.2. Geometries in pyFAI 35
![Page 40: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/40.jpg)
pyFAI Documentation, Release 0.15.0a0
Detector Detector Spline= None PixelSize= 1.000e-04, 1.000e-04 mWavelength= 1.000000e-10mSampleDetDist= 1.000000e+00m PONI= 5.000000e-02, 5.000000e-02m rot1=0.→˓000000 rot2= 0.200000 rot3= 0.000000 radDirectBeamDist= 1020.339mm Center: x=500.000, y=2527.100 pix Tilt=11.459→˓deg tiltPlanRotation= 90.000 deg
<IPython.core.display.Javascript object>
<matplotlib.axes._subplots.AxesSubplot at 0x7f2015f33160>
So a positive rot2 is equivalent to turning the detector to the down, around the sample position (where the observeris).
Now we can combine the two first rotations and check for the effect of the third rotation.
rotation = +0.2ai.rot1 = rotationai.rot2 = rotationai.rot3 = 0print(ai)img = cal.fake_calibration_image(ai)
jupyter.display(img, label="rot1 = rot2 = 0.2 rad")
Detector Detector Spline= None PixelSize= 1.000e-04, 1.000e-04 mWavelength= 1.000000e-10mSampleDetDist= 1.000000e+00m PONI= 5.000000e-02, 5.000000e-02m rot1=0.→˓200000 rot2= 0.200000 rot3= 0.000000 radDirectBeamDist= 1041.091mm Center: x=-1527.100, y=2568.329 pix Tilt=16.151→˓deg tiltPlanRotation= 134.423 deg
<IPython.core.display.Javascript object>
<matplotlib.axes._subplots.AxesSubplot at 0x7f2015efa780>
rotation = +0.2import copyai2 = copy.copy(ai)ai2.rot1 = rotationai2.rot2 = rotationai2.rot3 = rotationprint(ai2)img2 = cal.fake_calibration_image(ai2)
jupyter.display(img2, label="rot1 = rot2 = rot3 = 0.2 rad")
Detector Detector Spline= None PixelSize= 1.000e-04, 1.000e-04 mWavelength= 1.000000e-10mSampleDetDist= 1.000000e+00m PONI= 5.000000e-02, 5.000000e-02m rot1=0.→˓200000 rot2= 0.200000 rot3= 0.200000 radDirectBeamDist= 1041.091mm Center: x=-1527.100, y=2568.329 pix Tilt=16.151→˓deg tiltPlanRotation= 134.423 deg
<IPython.core.display.Javascript object>
<matplotlib.axes._subplots.AxesSubplot at 0x7f2015e56128>
36 Chapter 3. Tutorials
![Page 41: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/41.jpg)
pyFAI Documentation, Release 0.15.0a0
If one considers the rotation along the incident beam, there is no visible effect on the image as the image isinvariant along this transformation.
To actually see the effect of this third rotation one needs to perform the azimuthal integration and display the resultwith properly labeled axes.
fig, ax = subplots(1,2,figsize=(10,5))
res1 = ai.integrate2d(img, 300, 360, unit="2th_deg")jupyter.plot2d(res1, label="rot3 = 0 rad", ax=ax[0])
res2 = ai2.integrate2d(img2, 300, 360, unit="2th_deg")jupyter.plot2d(res2, label="rot3 = 0.2 rad", ax=ax[1])
<IPython.core.display.Javascript object>
<matplotlib.axes._subplots.AxesSubplot at 0x7f2015dee4a8>
So the increasing rot3 creates more negative azimuthal angles: it is like rotating the detector clockwise around theincident beam.
Conclusion
All 3 translations and all 3 rotations can be summarized in the following figure:
Fig. 3.1: PONI figure
It may appear strange to have (x_1, x_2, x_3) indirect indirect but this has been made in such a way chi, theazimuthal angle, is 0 along x_2 and 90_deg along x_1 (and not vice-versa).
3.2. Geometries in pyFAI 37
![Page 42: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/42.jpg)
pyFAI Documentation, Release 0.15.0a0
print("Processing time: %.3fs"%(time.time()-start_time))
Processing time: 7.502s
Detector distortion corrections
This tutorial shows how to correct images for spatial distortion. Some tutorial examples rely on files available inhttp://www.silx.org/pub/pyFAI/testimages/ and will be downloaded during this tutorial. The requiered minimumversion of pyFAI is 0.12.0.
Detector definitions
PyFAI features an impressive list of 58 detector definitions contributed often by manufacturers and some otherreverse engineerd by scientists. Each of them is defined as an invividual class which contains a way to calculatethe mask (invalid pixels, gaps,. . . ) and a method to calculate the pixel positions in Cartesian coordinates.
import timestart_time = time.time()import pyFAIprint("pyFAI version:" + pyFAI.version)all_detectors = list(set(pyFAI.detectors.ALL_DETECTORS.values()))#Sort detectors according to their nameall_detectors.sort(key=lambda i:i.__name__)nb_det = len(all_detectors)print("Number of detectors registered: %i with %i unique detectors"%(len(pyFAI.→˓detectors.ALL_DETECTORS),nb_det))print()print("List of all supported detectors")for i in all_detectors:
print(i())
pyFAI version:0.14.0-dev4Number of detectors registered: 167 with 58 unique detectors
List of all supported detectorsDetector Quantum 210 Spline= None PixelSize= 5.100e-05, 5.100e-05 mDetector Quantum 270 Spline= None PixelSize= 6.480e-05, 6.480e-05 mDetector Quantum 315 Spline= None PixelSize= 5.100e-05, 5.100e-05 mDetector Quantum 4 Spline= None PixelSize= 8.200e-05, 8.200e-05 mDetector Aarhus Spline= None PixelSize= 2.500e-05, 2.500e-05 mDetector ApexII PixelSize= 1.200e-04, 1.200e-04 mDetector aca1300 PixelSize= 3.750e-06, 3.750e-06 mUndefined detectorDetector Dexela 2923 PixelSize= 7.500e-05, 7.500e-05 mDetector Eiger 16M PixelSize= 7.500e-05, 7.500e-05 mDetector Eiger 1M PixelSize= 7.500e-05, 7.500e-05 mDetector Eiger 4M PixelSize= 7.500e-05, 7.500e-05 mDetector Eiger 500k PixelSize= 7.500e-05, 7.500e-05 mDetector Eiger 9M PixelSize= 7.500e-05, 7.500e-05 mDetector Fairchild PixelSize= 1.500e-05, 1.500e-05 mDetector HF-130k Spline= None PixelSize= 1.500e-04, 1.500e-04 mDetector HF-1M Spline= None PixelSize= 1.500e-04, 1.500e-04 mDetector HF-262k Spline= None PixelSize= 1.500e-04, 1.500e-04 mDetector HF-2.4M Spline= None PixelSize= 1.500e-04, 1.500e-04 mDetector HF-4M Spline= None PixelSize= 1.500e-04, 1.500e-04 mDetector HF-9.4M Spline= None PixelSize= 1.500e-04, 1.500e-04 mDetector Imxpad S10 PixelSize= 1.300e-04, 1.300e-04 m
38 Chapter 3. Tutorials
![Page 43: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/43.jpg)
pyFAI Documentation, Release 0.15.0a0
Detector Imxpad S140 PixelSize= 1.300e-04, 1.300e-04 mDetector Imxpad S70 PixelSize= 1.300e-04, 1.300e-04 mDetector MAR 345 PixelSize= 1.000e-04, 1.000e-04 mDetector Perkin detector PixelSize= 2.000e-04, 2.000e-04 mDetector Pilatus 100k PixelSize= 1.720e-04, 1.720e-04 mDetector Pilatus 1M PixelSize= 1.720e-04, 1.720e-04 mDetector Pilatus 200k PixelSize= 1.720e-04, 1.720e-04 mDetector Pilatus 2M PixelSize= 1.720e-04, 1.720e-04 mDetector Pilatus 300k PixelSize= 1.720e-04, 1.720e-04 mDetector Pilatus 300kw PixelSize= 1.720e-04, 1.720e-04 mDetector Pilatus 6M PixelSize= 1.720e-04, 1.720e-04 mDetector Pilatus CdTe 1M PixelSize= 1.720e-04, 1.720e-04 mDetector Pilatus CdTe 2M PixelSize= 1.720e-04, 1.720e-04 mDetector Pilatus CdTe 300k PixelSize= 1.720e-04, 1.720e-04 mDetector Pilatus CdTe 300kw PixelSize= 1.720e-04, 1.720e-04 mDetector Pixium 4700 detector PixelSize= 3.080e-04, 3.080e-04 mDetector Picam v1 Spline= None PixelSize= 1.400e-06, 1.400e-06 mDetector Picam v2 Spline= None PixelSize= 1.120e-06, 1.120e-06 mDetector Rayonix PixelSize= 3.200e-05, 3.200e-05 mDetector MAR133 PixelSize= 6.400e-05, 6.400e-05 mDetector Rayonix LX170 PixelSize= 4.427e-05, 4.427e-05 mDetector Rayonix LX255 PixelSize= 4.427e-05, 4.427e-05 mDetector Rayonix MX170 PixelSize= 4.427e-05, 4.427e-05 mDetector Rayonix MX225 PixelSize= 7.324e-05, 7.324e-05 mDetector Rayonix MX225HS PixelSize= 7.813e-05, 7.813e-05 mDetector Rayonix mx300 PixelSize= 7.324e-05, 7.324e-05 mDetector Rayonix MX300HS PixelSize= 7.813e-05, 7.813e-05 mDetector Rayonix MX325 PixelSize= 7.935e-05, 7.935e-05 mDetector Rayonix MX340HS PixelSize= 8.854e-05, 8.854e-05 mDetector Rayonix MX425HS PixelSize= 4.427e-05, 4.427e-05 mDetector MAR165 PixelSize= 3.950e-05, 3.950e-05 mDetector Rayonix sx200 PixelSize= 4.800e-05, 4.800e-05 mDetector Rayonix SX30HS PixelSize= 1.563e-05, 1.563e-05 mDetector Rayonix SX85HS PixelSize= 4.427e-05, 4.427e-05 mDetector Titan 2k x 2k PixelSize= 6.000e-05, 6.000e-05 mDetector Xpad S540 flat PixelSize= 1.300e-04, 1.300e-04 m
Defining a detector from a spline file
For optically coupled CCD detectors, the geometrical distortion is often described by a two-dimensional cubicspline (as in FIT2D) which can be imported into the relevant detector instance and used to calculate the actualpixel position in space (and masked pixels).
At the ESRF, mainly FReLoN detectors [J.-C. Labiche, ESRF Newsletter 25, 41 (1996)] are used with spline filesdescribing the distortion of the fiber optic taper.
Let’s download such a file and create a detector from it. Users at ESRF may declare a proxy to connect to theinternet.
import osos.environ["http_proxy"] = "http://proxy.esrf.fr:3128"from silx.resources import ExternalResourcesdownloader = ExternalResources("pyFAI", "http://www.silx.org/pub/pyFAI/testimages",→˓ "PYFAI_DATA")spline_file = downloader.getfile("halfccd.spline")print(spline_file)
/tmp/pyFAI_testdata_kieffer/halfccd.spline
3.3. Detector distortion corrections 39
![Page 44: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/44.jpg)
pyFAI Documentation, Release 0.15.0a0
hd = pyFAI.detectors.FReLoN(splineFile=spline_file)print(hd)print("Shape: %i, %i"% hd.shape)
Detector FReLoN Spline= /tmp/pyFAI_testdata_kieffer/halfccd.spline→˓PixelSize= 4.842e-05, 4.684e-05 mShape: 1025, 2048
Note the unusual shape of this detector. This is probably a human error when calibrating the detector distortion inFIT2D.
Visualizing the mask
Every detector object contains a mask attribute, defining pixels which are invalid. For FReLoN detector (a spline-files-defined detectors), all pixels having an offset such that the pixel falls out of the initial detector are consideredas invalid.
Masked pixel have non-null values can be displayed like this:
%pylab nbaggfrom pyFAI.gui import jupyter
Populating the interactive namespace from numpy and matplotlib
jupyter.display(hd.mask, label="Mask")
<IPython.core.display.Javascript object>
<matplotlib.axes._subplots.AxesSubplot at 0x7f96412a5240>
Detector definition files as NeXus files
Any detector object in pyFAI can be saved into an HDF5 file following the NeXus convention [Könnecke et al.,2015, J. Appl. Cryst. 48, 301-305.]. Detector objects can subsequently be restored from disk, making complexdetector definitions less error prone.
h5_file = "halfccd.h5"hd.save(h5_file)new_det = pyFAI.detector_factory(h5_file)print(new_det)print("Mask is the same: ", numpy.allclose(new_det.mask, hd.mask))print("Pixel positions are the same: ", numpy.allclose(new_det.get_pixel_corners(),→˓ hd.get_pixel_corners()))print("Number of masked pixels", new_det.mask.sum())
FReLoN detector from NeXus file: halfccd.h5 PixelSize= 4.842e-05, 4.684e-05 mMask is the same: TruePixel positions are the same: TrueNumber of masked pixels 34382
Pixels of an area detector are saved as a four-dimensional dataset: i.e. a two-dimensional array of vertices pointingto every corner of each pixel, generating an array of dimension (Ny, Nx, Nc, 3), where Nx and Ny are thedimensions of the detector, Nc is the number of corners of each pixel, usually four, and the last entry contains thecoordinates of the vertex itself (in the order: Z, Y, X).
This kind of definition, while relying on large description files, can address some of the most complex detectorlayouts. They will be presented a bit later in this tutorial.
40 Chapter 3. Tutorials
![Page 45: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/45.jpg)
pyFAI Documentation, Release 0.15.0a0
print("Size of Spline-file:", os.stat(spline_file).st_size)print("Size of Nexus-file:", os.stat(h5_file).st_size)
Size of Spline-file: 1183Size of Nexus-file: 21451707
The HDF5 file is indeed much larger than the spline file.
Modify a detector and saving
One may want to define a new mask (or flat-field) for its detector and save the mask with the detector definition.Here, we create a copy of the detector and reset its mask to enable all pixels in the detector and save the newdetector instance into another file.
import copynomask_file = "nomask.h5"nomask = copy.deepcopy(new_det)nomask.mask = numpy.zeros_like(new_det.mask)nomask.save(nomask_file)nomask = pyFAI.detector_factory("nomask.h5")print("No pixels are masked",nomask.mask.sum())
No pixels are masked 0
Wrap up
In this section we have seen how detectors are defined in pyFAI, how they can be created, either from the listof the parametrized ones, or from spline files, or from NeXus detector files. We have also seen how to save andsubsequently restore a detector instance, preserving the modifications made.
Distortion correction
Once the position of every single pixel in space is known, one can benefit from the regridding engine of pyFAIadapted to image distortion correction tasks. The pyFAI.distortion.Distortion class is the equivalent of the py-FAI.AzimuthalIntegrator for distortion. Provided with a detector definition, it enables the correction of a set ofimages by using the same kind of look-up tables as for azimuthal integration.
from pyFAI.distortion import Distortiondis = Distortion(nomask)print(dis)
Distortion correction csr on device None for detector shape (1025, 2048):NexusDetector detector from NeXus file: nomask.h5 PixelSize= 4.842e-05, 4.684e-→˓05 m
FReLoN detector
First load the image to be corrected, then correct it for geometric distortion.
halfccd_img = downloader.getfile("halfccd.edf")import fabioraw = fabio.open(halfccd_img).datacor = dis.correct(raw, dummy=raw.min())
#Then display raw and corrected imagesimagesfig, ax = subplots(2, figsize=(8,8))
3.3. Detector distortion corrections 41
![Page 46: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/46.jpg)
pyFAI Documentation, Release 0.15.0a0
jupyter.display(raw, label="Raw Image", ax=ax[0])jupyter.display(cor, label="Corrected image", ax=ax[1])
ERROR:pyFAI.distortion:The image shape ((1024, 2048)) is not the same as the→˓detector ((1025, 2048)). Adapting shape ...
<IPython.core.display.Javascript object>
<matplotlib.axes._subplots.AxesSubplot at 0x7f963f4ca198>
Nota: in this case the image size (1024 lines) does not match the detector’s number of lines (1025) hence pyFAIcomplains about it. Here, pyFAI patched the image on an empty image of the right size so that the processing canoccur.
In this example, the size of the pixels and the shape of the detector are preserved, discarding all pixels fallingoutside the detector’s grid.
One may want all pixels’ intensity to be preserved in the transformation. By allowing the output array to be largeenough to accomodate all pixels, the total intensity can be kept. For this, just enable the “resize” option in theconstructor of Distortion:
dis1 = Distortion(hd, resize=True)cor = dis1.correct(raw)print(dis1)print("After correction, the image has a different shape", cor.shape)
ERROR:pyFAI.distortion:The image shape ((1024, 2048)) is not the same as the→˓detector ((1025, 2048)). Adapting shape ...
Distortion correction csr on device None for detector shape (1045, 2052):Detector FReLoN Spline= /tmp/pyFAI_testdata_kieffer/halfccd.spline→˓PixelSize= 4.842e-05, 4.684e-05 mAfter correction, the image has a different shape (1045, 2052)
fig, ax = subplots(2,figsize=(8,8))jupyter.display(raw, label="Raw Image", ax=ax[0])jupyter.display(cor, label="Corrected image", ax=ax[1])
<IPython.core.display.Javascript object>
<matplotlib.axes._subplots.AxesSubplot at 0x7f963f46a4a8>
Example of Pixel-detectors:
XPad Flat detector
There is a striking example in the cover image of this article: http://scripts.iucr.org/cgi-bin/paper?S1600576715004306 where a detector made of multiple modules is eating up some rings. The first examplewill be about the regeneration of an “eyes friendly” version of this image.
xpad_file = downloader.getfile("LaB6_18.57keV_frame_13.edf")xpad = pyFAI.detector_factory("Xpad_flat")print(xpad)xpad_dis = Distortion(xpad, resize=True)
raw = fabio.open(xpad_file).datacor = xpad_dis.correct(raw)
42 Chapter 3. Tutorials
![Page 47: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/47.jpg)
pyFAI Documentation, Release 0.15.0a0
print("Shape as input and output:", raw.shape, cor.shape)print("Conservation of the total intensity:", raw.sum(dtype="float64"), cor.→˓sum(dtype="float64"))
#then display images side by sidefig, ax = subplots(1, 2, figsize=(8,8))jupyter.display(raw, label="Raw Image", ax=ax[0])jupyter.display(cor, label="Corrected image", ax=ax[1])
Detector Xpad S540 flat PixelSize= 1.300e-04, 1.300e-04 mShape as input and output: (960, 560) (1153, 578)Conservation of the total intensity: 11120798.0 11120798.0549
<IPython.core.display.Javascript object>
<matplotlib.axes._subplots.AxesSubplot at 0x7f963f38d7b8>
WOS XPad detector
This is a new WAXS opened for SAXS pixel detector from ImXPad (available at ESRF-BM02/D2AM CRGbeamline). It looks like two of XPad_flat detectors side by side with some modules shifted in order to create ahole to accomodate a flight-tube which gathers the SAXS photons to a second detector further away.
The detector definition for this specific detector has directly been put down using the metrology informations fromthe manufacturer and saved as a NeXus detector definition file.
wos_det = downloader.getfile("WOS.h5")wos_img = downloader.getfile("WOS.edf")wos = pyFAI.detector_factory(wos_det)print(wos)wos_dis = Distortion(wos, resize=True)
raw = fabio.open(wos_img).datacor = wos_dis.correct(raw)print("Shape as input: %s and output: %s"%( raw.shape, cor.shape))print("Conservation of the total intensity: %.4e vs %.4e "%(raw.sum(dtype="float64→˓"), cor.sum(dtype="float64")))#then display images side by sidefig, ax = subplots(2, figsize=(8,8))jupyter.display(raw, label="Raw Image", ax=ax[0])jupyter.display(cor, label="Corrected image", ax=ax[1])
NexusDetector detector from NeXus file: /tmp/pyFAI_testdata_kieffer/WOS.h5→˓PixelSize= 1.300e-04, 1.300e-04 mShape as input: (598, 1154) and output: (710, 1302)Conservation of the total intensity: 4.4436e+08 vs 4.4436e+08
<IPython.core.display.Javascript object>
<matplotlib.axes._subplots.AxesSubplot at 0x7f963f32bf60>
Nota: Do not use this detector definition file to process data from the WOS@D2AM as it has not (yet) been fullyvalidated and may contain some errors in the pixel positioning.
3.3. Detector distortion corrections 43
![Page 48: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/48.jpg)
pyFAI Documentation, Release 0.15.0a0
Conclusion
PyFAI provides a very comprehensive list of detector definitions, is versatile enough to address most area detectorson the market, and features a powerful regridding engine, both combined together into the distortion correctiontool which ensures the conservation of the signal during the transformation (the number of photons counted ispreserved during the transformation)
Distortion correction should not be used for pre-processing images prior to azimuthal integration as it re-bins theimage, thus induces a broadening of the peaks. The AzimuthalIntegrator object performs all this together withintegration, it has hence a better precision.
This tutorial did not answer the question how to calibrate the distortion of a given detector ? which is addressedin another tutorial called detector calibration.
print("Total execution time: %.3fs"%(time.time() - start_time))
Total execution time: 10.166s
Selection of a calibrant
In this tutorial we will see how to select a calibrant for a given experimental setup.
Experimental setup
The experimental setup is a classical protein crystallography setup with:
• Large Pilatus 6M detector on a translation table
• The small and intense beam of ~50 microns in size has a wavelength of 1 Angstrom
• The detector is in normal condition: orthogonal to the beam and centered in the middle of the detector.
The scientist in charge of this beamline want to ensure all encoders are working properly and needs to validatethe setup for distances between 10cm and 80cm. He will buy reference material from NIST but he does not knowwhich calibrant is best suited for his setup. We will assume all reference material sold by NIST are equally suitablefor ray position (no issue with grain size, ...).
The calibration works best in pyFAI if more than one Debye-Scherrer ring is seen on the detector.
Define the detector
import timestart_time = time.time()import pyFAIprint("PyFAI version" + pyFAI.version)dete = pyFAI.detectors.Pilatus6M()print(dete)
PyFAI version0.14.0-dev4Detector Pilatus 6M PixelSize= 1.720e-04, 1.720e-04 m
Select reference materials
The NIST sells different Standard Refrence Materials, among them Silicon (SRM640), Lanthanum hexaboride(SRM660), Alumina (SRM676) and Ceria (SRM674) are commonly used. Many other exists: Cr203, TiO2, Zn0,SiO2, ... Evaluating them is left as an exercise.
44 Chapter 3. Tutorials
![Page 49: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/49.jpg)
pyFAI Documentation, Release 0.15.0a0
import pyFAI.calibrantprint(pyFAI.calibrant.ALL_CALIBRANTS)
Calibrants available: Au, LaB6_SRM660c, CrOx, CuO, Cr2O3, Si_SRM640c, CeO2, AgBh,→˓cristobaltite, TiO2, PBBA, C14H30O, Al, LaB6, NaCl, ZnO, mock, LaB6_SRM660a, Si_→˓SRM640a, LaB6_SRM660b, alpha_Al2O3, Si_SRM640e, Si_SRM640, Si_SRM640b, quartz,→˓Ni, Si, Si_SRM640d
You may wonder where the names of the calibrant came from and how they have been established.
The name of all calibrant available in your version of pyFAI can be listed by just printing out the content ofALL_CALIBRANTS. New calibrant may have been added in pyFAI in more recent releases, just have a look atthe developent web page.
Most of those calibrant files, which contain the d-spacing in Angstrom between Miller plans, have been preparedfrom the unit cell of the compount, found in publication. This publication is referenced in the header of the file. Ifone wishes to regenerate those files, the pyFAI.calibrant.Cell class may be used for.
We will now focus on a subset of calibrant, instanciate them and put them into a dictionnary. The Python constructused here is called dict-comprehension and allows the creation and population of a dictionnary in a single line.
cals = dict((name,pyFAI.calibrant.ALL_CALIBRANTS(name)) for name in ("Si", "LaB6",→˓"CeO2", "alpha_Al2O3"))print(cals)
{'alpha_Al2O3': alpha_Al2O3 Calibrant , 'Si': Si Calibrant , 'CeO2': CeO2→˓Calibrant , 'LaB6': LaB6 Calibrant }
To be able to use those calibrants, one needs to define the wavelength used, here 1 Angstrom.
wl = 1e-10for cal in cals.values():
cal.wavelength = wlprint(cals)
{'alpha_Al2O3': alpha_Al2O3 Calibrant at wavelength 1e-10, 'Si': Si Calibrant at→˓wavelength 1e-10, 'CeO2': CeO2 Calibrant at wavelength 1e-10, 'LaB6': LaB6→˓Calibrant at wavelength 1e-10}
Short distance images
The shortest the detector can come to the sample is about 10cm (to leave space for the beamstop). We will generateimages of diffraction at this distance.
For the display of images we will use matplotlib inlined and some utilities from pyFAI to display images.
p1, p2, p3 = dete.calc_cartesian_positions()poni1 = p1.mean()poni2 = p2.mean()print("Detector center at %s, %s"%(poni1, poni2))ai_short = pyFAI.AzimuthalIntegrator(dist=0.1, poni1=poni1, poni2=poni2,→˓detector=dete)print(ai_short)
Detector center at 0.217322, 0.211818Detector Pilatus 6M PixelSize= 1.720e-04, 1.720e-04 mSampleDetDist= 1.000000e-01m PONI= 2.173222e-01, 2.118181e-01m rot1=0.→˓000000 rot2= 0.000000 rot3= 0.000000 radDirectBeamDist= 100.000mm Center: x=1231.500, y=1263.501 pix Tilt=0.000 deg→˓ tiltPlanRotation= 0.000 deg
3.4. Selection of a calibrant 45
![Page 50: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/50.jpg)
pyFAI Documentation, Release 0.15.0a0
%pylab nbaggfrom pyFAI.gui import jupyter
Populating the interactive namespace from numpy and matplotlib
fig, ax = subplots(2, 2, figsize=(10,10))for idx, key in enumerate(cals):
cal = cals[key]img = cal.fake_calibration_image(ai_short)jupyter.display(img, label=key, ax=ax[idx//2, idx%2])
<IPython.core.display.Javascript object>
As one can see, there are plenty of rings on the image: it should be easy to calibrate. By moving further away thedetector, the number of rings will decrease.
Long distance images
To keep good calibration one should have at lease two rings for the calibration. The longest distance from sampleto the detector is 80cm.
ai_long = pyFAI.AzimuthalIntegrator(dist=0.8, poni1=poni1, poni2=poni2,→˓detector=dete)print(ai_long)
Detector Pilatus 6M PixelSize= 1.720e-04, 1.720e-04 mSampleDetDist= 8.000000e-01m PONI= 2.173222e-01, 2.118181e-01m rot1=0.→˓000000 rot2= 0.000000 rot3= 0.000000 radDirectBeamDist= 800.000mm Center: x=1231.500, y=1263.501 pix Tilt=0.000 deg→˓ tiltPlanRotation= 0.000 deg
fig, ax = subplots(2, 2, figsize=(10,10))for idx, key in enumerate(cals):
cal = cals[key]img = cal.fake_calibration_image(ai_long)jupyter.display(img, label=key, ax=ax[idx//2, idx%2])
<IPython.core.display.Javascript object>
The most adapted calibrant is probably the LaB6 as 2 rings are still visible at 80 cm from the detector.
Integration of the pattern for the two extreme cases
We can integrate the image for the two extreme cases:
lab6 = cals["LaB6"]ai_short.wavelength = ai_long.wavelength = wl
fig, ax = subplots(2, 2, figsize=(10,10))img_short = lab6.fake_calibration_image(ai_short)jupyter.display(img_short, label="LaB6 d=0.1m", ax=ax[0,0])jupyter.plot1d(ai_short.integrate1d(img_short,1000), ax=ax[0,1])
img_long = lab6.fake_calibration_image(ai_long)jupyter.display(img_long, label="LaB6 d=0.8m", ax=ax[1,0])jupyter.plot1d(ai_long.integrate1d(img_long,1000), ax=ax[1,1])
46 Chapter 3. Tutorials
![Page 51: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/51.jpg)
pyFAI Documentation, Release 0.15.0a0
<IPython.core.display.Javascript object>
<matplotlib.axes._subplots.AxesSubplot at 0x7fa82229bd30>
Conclusion
The best calibrant in this case is probably LaB6.
print("Total execution time: %.3fs"%(time.time()-start_time))
Total execution time: 16.044s
Multi-geometry azimuthal integration
Or how it is possible to perform an azimuthal regrouping using multiple detectors or by moving a single (small)detector to cover more solid angle.
Idea
Azimuthal integration or azimuthal regrouping is (roughly) the averaging of all pixel intensities with the same Qvalue (or 2theta), as described in this publication chapter 3.2 and 3.3.
By taking multiple images at various places in space one covers more solid angle, allowing either a better statisticsor a larger Q-range coverage.
As described in the publication, the average is calculated by the ratio of the (intensity-) weighted histogram bythe unweighted histogram. By enforcing a same bin position over multiple geometries, one can create a combinedweighted and unweighted histograms by simply summing all partial histograms from each geometry.
The resulting pattern is obtained as usual by the ration of weighted/unweighted
How it works
Lets assume you are able to know where your detector is in space, either calibrated, either calculated from thegoniometer position. A diffrection image (img_i) has been acquired using a geometry which is stored in a poni-file(poni_i) useable by pyFAI.
To define a multi-geometry integrator, one needs all poni-files and one needs to define the output space so that allindividual integrators use the same bins.
import globimport fabiofrom pyFAI.multi_geometry import MultiGeometry
img_files = glob.glob("*.cbf")img_data = [fabio.open(i).data for i in img_files]ais = [i[:-4]+".poni" for i in img_files]mg = MultiGeometry(ais, unit="q_A^-1", radial_range=(0, 50), wavelength=1e-10)q, I = mg.integrate1d(img_data, 10000)
What is automatic
• MultiGeometry takes care of defining the same output space with the same bin position,
• It performs the normalization of the solid angle (absolute solid angle, unlike AzimuthalIntegrator !)
3.5. Multi-geometry azimuthal integration 47
![Page 52: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/52.jpg)
pyFAI Documentation, Release 0.15.0a0
• It can handle polarization correction if needed
• It can normalize by a monitor (I1 normalization) or correct for exposure time
What is not
For PDF measurement, data needs to be properly prepared, especially:
• Dark current subtraction
• Flat-field correction
• Exposure time correction (if all images are not taken with the same exposure time)
Examples
Demo of usage of the MultiGeometry class of pyFAI
For this tutorial, we will use the Jupyter notebook, formerly known as ipython, an take advantage of the integrationof matplotlib.
%pylab nbaggimport timestart_time = time.time()from pyFAI.gui import jupyter
Populating the interactive namespace from numpy and matplotlib
The multi_geometry module of pyFAI allows you to integrate multiple images taken at various image position, alltogeather. This tutorial will explain you how to perform azimuthal integration in three use-case: translation of thedetector, rotation of the detector around the sample and finally how to fill gaps of a pixel detector. But before, weneed to know how to generate fake diffraction image.
Generation of diffraction images
PyFAI knows about 20 different reference sample called calibrants. We will use them to generate fake diffractionimages knowing the detector and its position in space
import pyFAIimport pyFAI.calibrantprint("Number of known calibrants: %s"%len(pyFAI.calibrant.ALL_CALIBRANTS))print(", ".join(pyFAI.calibrant.ALL_CALIBRANTS.keys()))
Number of known calibrants: 28CuO, LaB6_SRM660c, TiO2, Si_SRM640a, AgBh, LaB6_SRM660a, Si, LaB6_SRM660b, mock,→˓cristobaltite, Ni, CrOx, alpha_Al2O3, Si_SRM640, ZnO, Si_SRM640b, CeO2, LaB6,→˓PBBA, Si_SRM640c, Si_SRM640e, Al, quartz, Cr2O3, Au, C14H30O, NaCl, Si_SRM640d
wavelength = 1e-10LaB6 = pyFAI.calibrant.get_calibrant("LaB6")LaB6.set_wavelength(wavelength)print(LaB6)print("Number of reflections for calibrant at given wavelength: %i"%len(LaB6.get_→˓dSpacing()))
LaB6 Calibrant at wavelength 1e-10Number of reflections for calibrant at given wavelength: 59
48 Chapter 3. Tutorials
![Page 53: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/53.jpg)
pyFAI Documentation, Release 0.15.0a0
We will start with a “simple” detector called Titan (build by Oxford Diffraction but now sold by Agilent). It is aCCD detector with scintilator and magnifying optics fibers. The pixel size is constant: 60µm
det = pyFAI.detectors.Titan()print(det)p1, p2, p3 = det.calc_cartesian_positions()print("Detector is flat, P3= %s"%p3)poni1 = p1.mean()poni2 = p2.mean()print("Center of the detector: poni1=%s poni2=%s"%(poni1, poni2))
Detector Titan 2k x 2k PixelSize= 6.000e-05, 6.000e-05 mDetector is flat, P3= NoneCenter of the detector: poni1=0.06144 poni2=0.0614399
The detector is placed orthogonal to the beam at 10cm. This geometry is saved into an AzimuthalIntegratorinstance:
ai = pyFAI.AzimuthalIntegrator(dist=0.1, poni1=poni1, poni2=poni2, detector=det,→˓wavelength=wavelength)print(ai)
Detector Titan 2k x 2k PixelSize= 6.000e-05, 6.000e-05 mWavelength= 1.000000e-10mSampleDetDist= 1.000000e-01m PONI= 6.144000e-02, 6.143988e-02m rot1=0.→˓000000 rot2= 0.000000 rot3= 0.000000 radDirectBeamDist= 100.000mm Center: x=1023.998, y=1024.000 pix Tilt=0.000 deg→˓ tiltPlanRotation= 0.000 deg
Knowing the calibrant, the wavelength, the detector and the geometry, one can simulate the 2D diffraction pattern:
img = LaB6.fake_calibration_image(ai)jupyter.display(img, label="Simulated LaB6")
<IPython.core.display.Javascript object>
<matplotlib.axes._subplots.AxesSubplot at 0x7f4bb7820c88>
This image can be integrated in q-space and plotted:
jupyter.plot1d(ai.integrate1d(img, 1000))
<IPython.core.display.Javascript object>
<matplotlib.axes._subplots.AxesSubplot at 0x7f4bb579fe48>
Note pyFAI does now about the ring position but nothing about relative intensities of rings.
Translation of the detector along the vertical axis
The vertical axis is defined along the poni1. If one moves the detector higher, the poni will appear at lowercoordinates. So lets define 5 upwards verical translations of half the detector size.
For this we will duplicate 5x the AzimuthalIntegrator object, but instances of AzimuthalIntegrator are mutable, soit is important to create an actual copy and not an view on them. In Python, one can use the copy function of thecopy module:
import copy
3.5. Multi-geometry azimuthal integration 49
![Page 54: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/54.jpg)
pyFAI Documentation, Release 0.15.0a0
We will now offset the poni1 value of each AzimuthalIntegratoe which correspond to a vertical translation. Eachsubsequent image is offsetted by half a detector width (stored as poni1).
ais = []imgs = []fig, ax = subplots(1,5, figsize=(10,2))for i in range(5):
my_ai = copy.deepcopy(ai)my_ai.poni1 -= i*poni1my_img = LaB6.fake_calibration_image(my_ai)jupyter.display(my_img, label="poni$_1$=%3.1fmm"%(1e3*my_ai.poni1), ax=ax[i])ais.append(my_ai)imgs.append(my_img)print(my_ai)
<IPython.core.display.Javascript object>
Detector Titan 2k x 2k PixelSize= 6.000e-05, 6.000e-05 mWavelength= 1.000000e-10mSampleDetDist= 1.000000e-01m PONI= 6.144000e-02, 6.143988e-02m rot1=0.→˓000000 rot2= 0.000000 rot3= 0.000000 radDirectBeamDist= 100.000mm Center: x=1023.998, y=1024.000 pix Tilt=0.000 deg→˓ tiltPlanRotation= 0.000 degDetector Titan 2k x 2k PixelSize= 6.000e-05, 6.000e-05 mWavelength= 1.000000e-10mSampleDetDist= 1.000000e-01m PONI= 0.000000e+00, 6.143988e-02m rot1=0.→˓000000 rot2= 0.000000 rot3= 0.000000 radDirectBeamDist= 100.000mm Center: x=1023.998, y=0.000 pix Tilt=0.000 deg→˓tiltPlanRotation= 0.000 degDetector Titan 2k x 2k PixelSize= 6.000e-05, 6.000e-05 mWavelength= 1.000000e-10mSampleDetDist= 1.000000e-01m PONI= -6.144000e-02, 6.143988e-02m rot1=0.→˓000000 rot2= 0.000000 rot3= 0.000000 radDirectBeamDist= 100.000mm Center: x=1023.998, y=-1024.000 pix Tilt=0.000 deg→˓ tiltPlanRotation= 0.000 degDetector Titan 2k x 2k PixelSize= 6.000e-05, 6.000e-05 mWavelength= 1.000000e-10mSampleDetDist= 1.000000e-01m PONI= -1.228800e-01, 6.143988e-02m rot1=0.→˓000000 rot2= 0.000000 rot3= 0.000000 radDirectBeamDist= 100.000mm Center: x=1023.998, y=-2048.000 pix Tilt=0.000 deg→˓ tiltPlanRotation= 0.000 degDetector Titan 2k x 2k PixelSize= 6.000e-05, 6.000e-05 mWavelength= 1.000000e-10mSampleDetDist= 1.000000e-01m PONI= -1.843200e-01, 6.143988e-02m rot1=0.→˓000000 rot2= 0.000000 rot3= 0.000000 radDirectBeamDist= 100.000mm Center: x=1023.998, y=-3072.000 pix Tilt=0.000 deg→˓ tiltPlanRotation= 0.000 deg
MultiGeometry integrator
The MultiGeometry instance can be created from any list of AzimuthalIntegrator instances or list of poni-files.Here we will use the former method.
The main difference of a MultiIntegrator with a “normal” AzimuthalIntegrator comes from the definition of theoutput space in the constructor of the object. One needs to specify the unit and the integration range.
from pyFAI.multi_geometry import MultiGeometry
mg = MultiGeometry(ais, unit="q_A^-1", radial_range=(0, 10))print(mg)
50 Chapter 3. Tutorials
![Page 55: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/55.jpg)
pyFAI Documentation, Release 0.15.0a0
MultiGeometry integrator with 5 geometries on (0, 10) radial range (q_A^-1) and (-→˓180, 180) azimuthal range (deg)
MultiGeometry integrators can be used in a similar way to “normal” AzimuthalIntegrators. Keep in mind theoutput intensity is always scaled to absolute solid angle.
ax = jupyter.plot1d(mg.integrate1d(imgs, 10000))
<IPython.core.display.Javascript object>
fig, ax = subplots()for idx, (i, a) in enumerate(zip(imgs, ais)):
jupyter.plot1d(a.integrate1d(i, 1000, unit="q_A^-1"), label="pos%i"%idx, ax=ax)
<IPython.core.display.Javascript object>
Rotation of the detector
The strength of translating the detector is that it simulates a larger detector, but this approach reaches its limitquikly as the higher the detector gets, the smallest the solid angle gets and induces artificial noise. One solution isto keep the detector at the same distance and rotate the detector.
This setup is common when mounting a detector on a goniometer.
Creation of diffraction images
In this example we will use a Pilatus 200k with 2 modules. It has a gap in the middle of the two detectors and wewill see how the MultiGeometry can help.
As previously, we will use LaB6 but instead of translating the images, we will rotate them along the second axis:
det = pyFAI.detectors.detector_factory("pilatus200k")p1, p2, p3 = det.calc_cartesian_positions()print(p3)poni1 = p1.mean()poni2 = p2.mean()print(poni1)print(poni2)
None0.0350020.041882
ai = pyFAI.AzimuthalIntegrator(dist=0.1, poni1=poni1, poni2=poni2, detector=det)img = LaB6.fake_calibration_image(ai)
jupyter.display(img, label="Pilatus 200k with LaB$_6$")
<IPython.core.display.Javascript object>
<matplotlib.axes._subplots.AxesSubplot at 0x7f4b9f09f2b0>
jupyter.plot1d(ai.integrate1d(img, 500,unit="2th_deg"))
<IPython.core.display.Javascript object>
3.5. Multi-geometry azimuthal integration 51
![Page 56: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/56.jpg)
pyFAI Documentation, Release 0.15.0a0
<matplotlib.axes._subplots.AxesSubplot at 0x7f4b9f0cdf28>
We will rotate the detector with a step size of 15 degrees
step = 15*pi/180ais = []imgs = []fig, ax = subplots(1, 5, figsize=(10,2))for i in range(5):
my_ai = copy.deepcopy(ai)my_ai.rot2 -= i*stepmy_img = LaB6.fake_calibration_image(my_ai)jupyter.display(my_img, label="Angle rot2: %.1f$^o$"%numpy.degrees(my_ai.rot2),
→˓ ax=ax[i])ais.append(my_ai)imgs.append(my_img)print(my_ai)
<IPython.core.display.Javascript object>
Detector Pilatus 200k PixelSize= 1.720e-04, 1.720e-04 mSampleDetDist= 1.000000e-01m PONI= 3.500200e-02, 4.188201e-02m rot1=0.→˓000000 rot2= 0.000000 rot3= 0.000000 radDirectBeamDist= 100.000mm Center: x=243.500, y=203.500 pix Tilt=0.000 deg→˓ tiltPlanRotation= 0.000 degDetector Pilatus 200k PixelSize= 1.720e-04, 1.720e-04 mSampleDetDist= 1.000000e-01m PONI= 3.500200e-02, 4.188201e-02m rot1=0.→˓000000 rot2= -0.261799 rot3= 0.000000 radDirectBeamDist= 103.528mm Center: x=243.500, y=47.716 pix Tilt=15.000 deg→˓tiltPlanRotation= -90.000 degDetector Pilatus 200k PixelSize= 1.720e-04, 1.720e-04 mSampleDetDist= 1.000000e-01m PONI= 3.500200e-02, 4.188201e-02m rot1=0.→˓000000 rot2= -0.523599 rot3= 0.000000 radDirectBeamDist= 115.470mm Center: x=243.500, y=-132.169 pix Tilt=30.000→˓deg tiltPlanRotation= -90.000 degDetector Pilatus 200k PixelSize= 1.720e-04, 1.720e-04 mSampleDetDist= 1.000000e-01m PONI= 3.500200e-02, 4.188201e-02m rot1=0.→˓000000 rot2= -0.785398 rot3= 0.000000 radDirectBeamDist= 141.421mm Center: x=243.500, y=-377.895 pix Tilt=45.000→˓deg tiltPlanRotation= -90.000 degDetector Pilatus 200k PixelSize= 1.720e-04, 1.720e-04 mSampleDetDist= 1.000000e-01m PONI= 3.500200e-02, 4.188201e-02m rot1=0.→˓000000 rot2= -1.047198 rot3= 0.000000 radDirectBeamDist= 200.000mm Center: x=243.500, y=-803.506 pix Tilt=60.000→˓deg tiltPlanRotation= -90.000 deg
fig, ax = subplots()for i, a in zip(imgs, ais):
jupyter.plot1d(a.integrate1d(i, 1000, unit="2th_deg"), label="%.1f$^o$"%numpy.→˓degrees(a.rot2), ax=ax)
<IPython.core.display.Javascript object>
Creation of the MultiGeometry
This time we will work in 2theta angle using degrees:
mg = MultiGeometry(ais, unit="2th_deg", radial_range=(0, 90))print(mg)
52 Chapter 3. Tutorials
![Page 57: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/57.jpg)
pyFAI Documentation, Release 0.15.0a0
fig, ax = subplots(2, 1, figsize=(8,12))jupyter.plot1d(mg.integrate1d(imgs, 10000), ax=ax[0])res2d = mg.integrate2d(imgs, 1000,360)jupyter.plot2d(res2d, ax=ax[1])
MultiGeometry integrator with 5 geometries on (0, 90) radial range (2th_deg) and (-→˓180, 180) azimuthal range (deg)
<IPython.core.display.Javascript object>
area_pixel=1.3223150558322514 area_sum=2.694867349304461, Error= -1.→˓0379918820544165
<matplotlib.axes._subplots.AxesSubplot at 0x7f4bb7552588>
How to fill-up gaps in arrays of pixel detectors during 2D integration
We will use ImXpad detectors which exhibits large gaps.
det = pyFAI.detectors.detector_factory("Xpad_flat")p1, p2, p3 = det.calc_cartesian_positions()print(p3)poni1 = p1.mean()poni2 = p2.mean()print(poni1)print(poni2)
None0.0748950.03757
ai = pyFAI.AzimuthalIntegrator(dist=0.1, poni1=0, poni2=poni2, detector=det)img = LaB6.fake_calibration_image(ai)jupyter.display(img, label="XPad S540 simulated LaB6")jupyter.plot2d(ai.integrate2d(img, 500, 360, azimuth_range=(0,180), unit="2th_deg",→˓ dummy=-1), label="2D")
<IPython.core.display.Javascript object>
<IPython.core.display.Javascript object>
<matplotlib.axes._subplots.AxesSubplot at 0x7f4bb74fe048>
To observe textures, it is mandatory to fill the large empty space. This can be done by tilting the detector by a fewdegrees to higher 2theta angle (yaw 2x5deg) and turn the detector along the azimuthal angle (roll 2x5deg):
step = 5*pi/180nb_geom = 3ais = []imgs = []for i in range(nb_geom):
for j in range(nb_geom):my_ai = copy.deepcopy(ai)my_ai.rot2 -= i*stepmy_ai.rot3 -= j*stepmy_img = LaB6.fake_calibration_image(my_ai)ais.append(my_ai)
3.5. Multi-geometry azimuthal integration 53
![Page 58: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/58.jpg)
pyFAI Documentation, Release 0.15.0a0
imgs.append(my_img)mg = MultiGeometry(ais, unit="2th_deg", radial_range=(0, 60), azimuth_range=(0,→˓180), empty=-5)print(mg)res2d = mg.integrate2d(imgs, 1000, 360)jupyter.plot2d(res2d, label="Filled")
MultiGeometry integrator with 9 geometries on (0, 60) radial range (2th_deg) and→˓(0, 180) azimuthal range (deg)
<IPython.core.display.Javascript object>
<matplotlib.axes._subplots.AxesSubplot at 0x7f4bb766a518>
As on can see, the gaps have disapeared and the statistics is much better, except on the border were only one imagecontributes to the integrated image.
Conclusion
The multi_geometry module of pyFAI makes powder diffraction experiments with small moving detectors mucheasier.
Some people would like to stitch input images together prior to integration. There are plenty of good tools to dothis: generalist one like Photoshop or more specialized ones like AutoPano. More seriously this can be using thedistortion module of a detector to re-sample the signal on a regular grid but one will have to store on one sidethe number of actual pixel contributing to a regular pixels and on the other the total intensity contained in theregularized pixel. Without the former information, doing science with a rebinned image is as meaningful as usingPhotoshop.
print("Excution time: %.3f"%(time.time()-start_time))
Excution time: 28.517
Conclusion
MultiGeometry is a unique feature of PyFAI ... While extremely powerful, it need careful understanding of thenumerical treatement going on underneath.
Creation of a calibrant file
In this tutorial we will see how to generate a file describing a reference material used as calibrant to refine thegeometry of the experimental setup, especially the position of the detector.
In pyFAI, calibrant are defined in a bunch of files available from github. Those files are automatically installedwith pyFAI and readily available from the programming interface, as described in the Calibrant tutorial.
This tutorials focuses on the content of the file and how to generate other calibrant files and how to exendedexisting ones.
Content of the file
Calibrant files from pyFAI are heavily inspired from the ones used in Fit2D: they simply store the d-spacingbetween Miller plans and are simply loaded using the numpy.loadtxt function. In pyFAI we have improved with
54 Chapter 3. Tutorials
![Page 59: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/59.jpg)
pyFAI Documentation, Release 0.15.0a0
plent of comment (using #) to provide in addition the familly of Miller plan associated and the multiplicity, which,while not proportionnal to Fobs is somewhat related.
One may think it would have been better/simpler to describe the cell of the material. Actually some calibrant,especially the ones used in SAXS like silver behenate (AgBh), but not only, are not well crystallized compoundsand providing the d-spacing allows to use them as calibrant. Neverthless this tutorial will be focused on how togenerate calibrant files fron crystal structures.
Finally the calibrant file has a few lines of headers containing the name, the crystal cell parameters (if available)and quite importantly a reference to the source of information like a publication to allow the re-generation of thefile if needed.
# Calibrant: Silver Behenate (AgBh)# Pseudocrystal a=inf b=inf c=58.380# Ref: doi:10.1107/S00218898990123885.83800000e+01 # (0,0,1)2.91900000e+01 # (0,0,2)1.94600000e+01 # (0,0,3)1.45950000e+01 # (0,0,4)1.16760000e+01 # (0,0,5)9.73000000e+00 # (0,0,6)8.34000000e+00 # (0,0,7)7.29750000e+00 # (0,0,8)6.48666667e+00 # (0,0,9)(...)
The Cell class
To generate a calibrant file from a crystal structure, the easiest is to use the pyFAI.calibrant.Cell class.
from pyFAI.calibrant import Cellprint(Cell.__doc__)print(Cell.__init__.__doc__)
This is a cell object, able to calculate the volume and d-spacing according to→˓formula from:
http://geoweb3.princeton.edu/research/MineralPhy/xtalgeometry.pdf
Constructor of the Cell class:
Crystalographic units are Angstrom for distances and degrees for angles !
:param a,b,c: unit cell length in Angstrom:param alpha, beta, gamma: unit cell angle in degrees:param lattice: "cubic", "tetragonal", "hexagonal", "rhombohedral",
→˓"orthorhombic", "monoclinic", "triclinic":param lattice_type: P, I, F, C or R
The constructor of the class is used to build and well suited to triclinic crystal.
Specific constructors
Nevertheless, most used calibrants are of much higher symmetry, like
cubic which takes only one parameter. | Here is an example for defining Polonium which is a simple cubic cell(Primitive) with a cell parameter of 335.9pm. This example was chosen as Polonium is apparently the only elementwith such primitive cubic packing.
3.6. Creation of a calibrant file 55
![Page 60: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/60.jpg)
pyFAI Documentation, Release 0.15.0a0
Po = Cell.cubic(3.359)print(Po)
Primitive cubic cell a=3.3590 b=3.3590 c=3.3590 alpha=90.000 beta=90.000 gamma=90.→˓000
print(Po.volume)
37.899197279
print("Po.d_spacing?")print(Po.d_spacing.__doc__)print("Po.save?")print(Po.save.__doc__)
Po.d_spacing?Calculate all d-spacing down to dmin
applies selection rules
:param dmin: minimum value of spacing requested:return: dict d-spacing as string, list of tuple with Miller indices
preceded with the numerical value
Po.save?Save informations about the cell in a d-spacing file, usable as Calibrant
:param name: name of the calibrant:param doi: reference of the publication used to parametrize the cell:param dmin: minimal d-spacing:param dest_dir: name of the directory where to save the result
To generate a d-spacing file usable as calibrant, one simply has to call the save method of the Cell instance.
Nota: the ”.D” suffix is automatically appended.
Po.save("Po",doi="http://www.periodictable.com/Elements/084/data.html", dmin=1)
with open("Po.D") as f:for l in f:
print(l.strip())
# Calibrant: Po# Primitive cubic cell a=3.3590 b=3.3590 c=3.3590 alpha=90.000 beta=90.000→˓gamma=90.000# Ref: http://www.periodictable.com/Elements/084/data.html3.35900000 # (1, 0, 0) 62.37517168 # (1, 1, 0) 121.93931955 # (1, 1, 1) 81.67950000 # (2, 0, 0) 61.50219047 # (2, 1, 0) 241.37130601 # (2, 1, 1) 241.18758584 # (2, 2, 0) 121.11966667 # (3, 0, 0) 301.06220907 # (3, 1, 0) 241.01277661 # (3, 1, 1) 24
56 Chapter 3. Tutorials
![Page 61: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/61.jpg)
pyFAI Documentation, Release 0.15.0a0
Other Examples: LaB6
Lantanide Hexaboride, probably my favorite calibrant as it has a primitive cubic cell hence all reflections are validand intense. The cell parameter is available from the NIST at a=4.156826.
The number of reflections in a file is controled by the dmin parameter. The lower it is, the more lines there are andthe more time-consuming this will be:
LaB6 = Cell.cubic(4.156826)%time d=LaB6.d_spacing(0.1)print("Number of reflections: %s"%len(d))
CPU times: user 2.7 s, sys: 8 ms, total: 2.71 sWall time: 2.71 sNumber of reflections: 1441
LaB6.save("my_LaB6",doi="https://www-s.nist.gov/srmors/certificates/660C.pdf",→˓dmin=0.1)
#Print the 10 first lines:with open("my_LaB6.D") as f:
for i, l in enumerate(f):if i<10:
print(l.strip())else:
break
# Calibrant: my_LaB6# Primitive cubic cell a=4.1568 b=4.1568 c=4.1568 alpha=90.000 beta=90.000→˓gamma=90.000# Ref: https://www-s.nist.gov/srmors/certificates/660C.pdf4.15682600 # (1, 0, 0) 62.93931985 # (1, 1, 0) 122.39994461 # (1, 1, 1) 82.07841300 # (2, 0, 0) 61.85898910 # (2, 1, 0) 241.69701711 # (2, 1, 1) 241.46965993 # (2, 2, 0) 12
Other Examples: Silicon
Silicon is easy to obtain pure thanks to microelectronics industry. Its cell is a face centered cubic with a diamondlike structure. The cell parameter is available from the NIST: a=5.431179 A.
Let’s compare the difference between the silicon structure and the equivalent FCC structure:
Si = Cell.diamond(5.431179)print(Si)
Face centered cubic cell a=5.4312 b=5.4312 c=5.4312 alpha=90.000 beta=90.000→˓gamma=90.000
FCC = Cell.cubic(5.431179, "F")print(FCC)
Face centered cubic cell a=5.4312 b=5.4312 c=5.4312 alpha=90.000 beta=90.000→˓gamma=90.000
Apparently, there is not difference. But to check it, let’s generate all lines down to 1A and compare them:
3.6. Creation of a calibrant file 57
![Page 62: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/62.jpg)
pyFAI Documentation, Release 0.15.0a0
sid = Si.d_spacing(1)for key, val in sid.items():
print("%s: %s"%(sorted(val[1:][-1]),key))
[2, 2, 4]: 1.10863477e+00[0, 0, 4]: 1.35779475e+00[1, 1, 1]: 3.13569266e+00[0, 2, 2]: 1.92021175e+00[1, 1, 5]: 1.04523089e+00[1, 3, 3]: 1.24599792e+00[1, 1, 3]: 1.63756208e+00
fccd = FCC.d_spacing(1)for key, val in fccd.items():
print("%s: %s"%(sorted(val[1:][-1]),key))
[2, 2, 2]: 1.56784633e+00[1, 3, 3]: 1.24599792e+00[2, 2, 4]: 1.10863477e+00[0, 0, 4]: 1.35779475e+00[0, 0, 2]: 2.71558950e+00[0, 2, 2]: 1.92021175e+00[1, 1, 5]: 1.04523089e+00[1, 1, 1]: 3.13569266e+00[0, 2, 4]: 1.21444854e+00[1, 1, 3]: 1.63756208e+00
So there are many more reflection in the FCC structure compared to the diamond-like structure: (4 2 0), (2 2 2)are extinct as h+k+l=4n and all even.
Selection rules
Cell object contain selection_rules which tells if a reflection is allowed or not. Those selection_rules can beintrospected:
print(Si.selection_rules)print(FCC.selection_rules)
[<function Cell.set_type.<locals>.<lambda> at 0x7f8a4dac0950>, <function Cell.set_→˓type.<locals>.<lambda> at 0x7f8a4dac08c8>, <function Cell.diamond.<locals>.→˓<lambda> at 0x7f8a4dac0840>][<function Cell.set_type.<locals>.<lambda> at 0x7f8a4dac09d8>, <function Cell.set_→˓type.<locals>.<lambda> at 0x7f8a4dac0730>]
The Si object has one additionnal selection rule which explains the difference: A specific rule telling that reflectionwith h+k+l=4n is forbidden when (h,k,l) are all even.
We will now have a look at the source code of those selection rules using the inspect module.
Nota: This is advanced Python hacking but useful for the demonstration
import inspectfor rule in Si.selection_rules:
print(inspect.getsource(rule).strip())
self.selection_rules = [lambda h, k, l: not(h == 0 and k == 0 and l == 0)]self.selection_rules.append(lambda h, k, l: (h % 2 + k % 2 + l % 2) in (0, 3))self.selection_rules.append(lambda h, k, l: not((h % 2 == 0) and (k % 2 == 0) and→˓(l % 2 == 0) and ((h + k + l) % 4 != 0)))
58 Chapter 3. Tutorials
![Page 63: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/63.jpg)
pyFAI Documentation, Release 0.15.0a0
Actually the last line correspond to an anonymous function (lambda) which implements this rule.
As we have seen previously one can simply adapt the Cell instance by simply appending extra selection rules tothis list.
A selection rule is a function taking 3 integers as input and returning True if the reflection is allowed and Falsewhen it is forbidden by symmetry. By this way one can simply adapt existing object to generate the right calibrantfile.
Conclusion
In this tutorial we have seen the structure of a calibrant file, how to generate crystal structure cell object to writesuch calibrant files automatically, including all metadata needed for redistribution. Most advanced programmerscan now modify the selection rules to remove forbidden reflection for a given cell.
CCD calibration
This tutorial presents how to calibrate the distortion from a CCD camera coupled with a taper of op-tic fibers. If your camera is already calibrated using Fit2D and you have access to the correspondingspline file, this tutorial is not for you: simply create your detector object like this pyFAI.detectors.Detector(splineFile="example.spline") and you are done. This tutorial uses the image of a regulargrid on the detector.
It uses a procedure described in: “Calibration and correction of spatial distortions in 2D detector systems” fromHammersley, A. P.; Svensson, S. O.; Thompson, A. published in Nuclear Instruments and Methods in PhysicsResearch Section A, Volume 346, Issue 1-2, p. 312-321. DOI:10.1016/0168-9002(94)90720-X
The procedure is performed in 4 steps: 1. peak picking 2. grid assignment 3. distortion fitting 4. interpolation ofthe fitted data 5. saving into a detector definition file
The picture used is the one of a regular metallic grid of holes (spaced by 5mm), just in front of the detector. Wewill assume holes are circular what looks correct in first approximation. Parallax error will be ignored in a firsttime.
The images used for this test can be downloaded from: http://www.silx.org/pub/pyFAI/detector_calibration/frelonID22_grid.edf
Peak picking
Lets start with peak picking, for this, we will use the FabIO library able to read the image and matplotlib to displaythe image. The distortion is assumed to be minimal in the middle of the detector, so we first focus on one spot inthe middle:
First we initialize the matplotlib library to be used in the Jupyter notebook interface.
%pylab nbaggimport timestart_time = time.time()
Populating the interactive namespace from numpy and matplotlib
import osos.environ["http_proxy"] = "http://proxy.esrf.fr:3128"from silx.resources import ExternalResourcesdownloader = ExternalResources("pyFAI", "http://www.silx.org/pub/pyFAI/detector_→˓calibration", "PYFAI_DATA")fname = downloader.getfile("frelonID22_grid.edf")print(fname)
3.7. CCD calibration 59
![Page 64: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/64.jpg)
pyFAI Documentation, Release 0.15.0a0
#To test the corrections are good:#fname = "corrected.edf"import fabioimg = fabio.open(fname).data
/tmp/pyFAI_testdata_kieffer/frelonID22_grid.edf
#Display the image, and zoom on one spotfig,ax = subplots(1, 2, figsize=(10,5))ax[0].imshow(img, interpolation="nearest", origin="lower")#Zoom into a spot in the middle of the image, where the distortion is expected to→˓be minimalax[1].imshow(img[1060:1100,1040:1080], interpolation="nearest", origin="lower")ax[1].set_title("Zoom one point in the center")
<IPython.core.display.Javascript object>
<matplotlib.text.Text at 0x7ff407100550>
#Look at the profile of the peak to measure the width (it is expected to be a→˓crenel)fig,ax = subplots()ax.plot(img[1060+25,1040:1060])
<IPython.core.display.Javascript object>
[<matplotlib.lines.Line2D at 0x7ff3df3fbf98>]
Let’s look at one spot, in the center of the image: it is circular and is slightly larger than 10 pixels. We will definea convolution kernel of size 11x11 of circular shape with sharp borders as this is what a perfect spot is expectedto look like. The kernel is normalized in such a way it does not modify the average intensity of the image
Now convolve the image with this circular kernel using scipy.signal (in direct space: the kernel is small andperformance does not really matter here).
It is important to have an odd size for the kernel for convolution as an even shape would induce an offset of 1/2pixel in the located peak-position.
size = 11 #Odd of coursecenter = (size-1)//2y, x = numpy.ogrid[-center:center+1,-center:center+1]r2 = x*x + y*ykernel = (r2<=(center+0.5)**2).astype(float)kernel /= kernel.sum()
fig,ax = subplots()ax.imshow(kernel, interpolation="nearest", origin="lower")
<IPython.core.display.Javascript object>
<matplotlib.image.AxesImage at 0x7ff40707dd68>
from scipy import ndimage, signal
cnv = signal.convolve2d(img, kernel, mode="same")
#Check that size is unchanged.print(img.shape)print(cnv.shape)
60 Chapter 3. Tutorials
![Page 65: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/65.jpg)
pyFAI Documentation, Release 0.15.0a0
(2048, 2048)(2048, 2048)
#Check the image still looks the same. it is just supposed to be smoother.
fig,ax = subplots(1,2, figsize=(10,5))ax[0].imshow(cnv, interpolation="nearest", origin="lower")#Zoom into a spot in the middle of the image, where the distortion is expected to→˓be minimalax[1].imshow(cnv[1060:1100,1040:1080], interpolation="nearest", origin="lower")ax[1].set_title("Zoom one point in the center")
<IPython.core.display.Javascript object>
<matplotlib.text.Text at 0x7ff3afe7ac50>
#Zoom into the very same spot to ensure it is smootherimshow(cnv[1060:1100,1040:1080], interpolation="nearest", origin="lower")
<matplotlib.image.AxesImage at 0x7ff3b01fbbe0>
# and here again the same profile:fig, ax = subplots()ax.plot(cnv[1060+25,1030:1070])# the peak got broader (2x) but much smoother on the top: this is what we are→˓interrested in.
<IPython.core.display.Javascript object>
[<matplotlib.lines.Line2D at 0x7ff3b020c8d0>]
After convolution with a pattern of the same shape as the hole, the peak center is located with a sub-pixel resolu-tion. The peak has a full size of 30 pixels in 1 dimension.
All peak positions will be extracted using the pyFAI inverse watershed algorithm. Once all regions are segmented,the ones too small are sieved out and the remaining ones are classifies according to their peak intensity using anhistogram. As intensity vary a lot, this histogram it is done on the log-scale of the intensity.
mini = (kernel>0).sum()print("Number of points in the kernel: %s"%mini)
Number of points in the kernel: 97
try: #depends if the version of pyFAI you are usingfrom pyFAI.watershed import InverseWatershed
except:from pyFAI.ext.watershed import InverseWatershed#Version of pyFAI newer than feb 2016
iw = InverseWatershed(cnv)iw.init()iw.merge_singleton()all_regions = set(iw.regions.values())regions = [i for i in all_regions if i.size>mini]
print("Number of region segmented: %s"%len(all_regions))print("Number of large enough regions : %s"%len(regions))
3.7. CCD calibration 61
![Page 66: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/66.jpg)
pyFAI Documentation, Release 0.15.0a0
Number of region segmented: 79513Number of large enough regions : 8443
s = [i.maxi for i in regions]
fig, ax = subplots()ax.hist(numpy.log10(s), 20)#Look for the maximum value in each region to be able to segment accordingly
<IPython.core.display.Javascript object>
(array([ 1.00000000e+00, 0.00000000e+00, 0.00000000e+00,0.00000000e+00, 0.00000000e+00, 0.00000000e+00,0.00000000e+00, 0.00000000e+00, 0.00000000e+00,1.00000000e+00, 2.85000000e+02, 5.99900000e+03,1.71900000e+03, 1.00000000e+00, 0.00000000e+00,1.00000000e+00, 3.00000000e+00, 2.30000000e+01,1.17000000e+02, 2.93000000e+02]),
array([ 2.05537045, 2.1621182 , 2.26886594, 2.37561369, 2.48236143,2.58910918, 2.69585692, 2.80260467, 2.90935241, 3.01610016,3.1228479 , 3.22959565, 3.33634339, 3.44309114, 3.54983888,3.65658663, 3.76333437, 3.87008212, 3.97682986, 4.08357761,4.19032535]),
<a list of 20 Patch objects>)
There are clearly 3 groups of very different intensity, well segregated:
• around 102.1 (~125), those are the peaks where no tapper brings light
• around 103.4 (~2500), those are segmented region in the background
• above 103.9 (~8000), those are actual peaks, we are looking for.
We retain all peaks >103.5
peaks = [(i.index//img.shape[-1], i.index%img.shape[-1]) for i in regions if (i.→˓maxi)>10**3.5]print("Number of remaining peaks: %s"%len(peaks))
Number of remaining peaks: 438
fix, ax = subplots()ax.imshow(img, interpolation="nearest", origin="lower")peaks_raw = numpy.array(peaks)plot(peaks_raw[:,1], peaks_raw[:, 0], "or")xlim(0,2048)ylim(0,2048)title("Extracted peak position (raw)")print("Raw peak coordinate:")print(peaks[:10])
<IPython.core.display.Javascript object>
Raw peak coordinate:[(595, 2013), (596, 744), (1288, 457), (1289, 260), (597, 644), (1289, 358), (1290,→˓ 163), (599, 545), (203, 1229), (1291, 67)]
62 Chapter 3. Tutorials
![Page 67: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/67.jpg)
pyFAI Documentation, Release 0.15.0a0
Precise peak extraction is performed using a second order tailor expansion
try:from pyFAI.bilinear import Bilinear
except:from pyFAI.ext.bilinear import Bilinear
bl = Bilinear(cnv)
ref_peaks = [bl.local_maxi(p) for p in peaks]fig, ax = subplots()ax.imshow(img, interpolation="nearest", origin="lower")peaks_ref = numpy.array(ref_peaks)ax.plot(peaks_raw[:,1], peaks_raw[:, 0], "or")ax.plot(peaks_ref[:,1],peaks_ref[:, 0], "ob")xlim(0,2048)ylim(0,2048)title("Extracted peak position (red: raw, blue: refined)")print("Refined peak coordinate:")print(ref_peaks[:10])
<IPython.core.display.Javascript object>
Refined peak coordinate:[(595.3652203381062, 2012.7038857638836), (595.8083281219006, 743.9954149895348),→˓(1287.5877491235733, 456.42732411623), (1289.217986062169, 259.9184771552682),→˓(597.122181430459, 644.3363811373711), (1288.529934734106, 357.8403638154268),→˓(1290.2493854910135, 162.8530249595642), (599.0024462197907, 544.8510167449713),→˓(202.7424472272396, 1229.3977319896221), (1290.644969880581, 66.39394468069077)]
At this stage, a visual inspection of the grid confirms all peaks have been properly segmented. If this is not thecase, one can adapt:
• the size of the kernel
• the threshold coming out of the histogramming
Pair-wise distribution function
We will now select the (4-) first neighbours for every single peak. For this we calculate the distance_matrix fromany point to any other:
# Nota, pyFAI uses **C-coordinates** so they come out as (y,x) and not the usual→˓(x,y).# This notation helps us to remind the orderyx = numpy.array(ref_peaks)
# pairwise distance calculation using scipy.spatial.distance_matrixfrom scipy.spatial import distance_matrixdist = distance_matrix(peaks_ref, peaks_ref)
Let’s have a look at the pairwise distribution function for the first neighbors
fig, ax = subplots()ax.hist(dist.ravel(), 200, range=(0,200))title("Pair-wise distribution function")
<IPython.core.display.Javascript object>
3.7. CCD calibration 63
![Page 68: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/68.jpg)
pyFAI Documentation, Release 0.15.0a0
<matplotlib.text.Text at 0x7ff3987668d0>
This histogram provides us:
• At 0, the 438 peaks with 0-distance to themselves.
• between 85 and 105 the first neighbours
• between 125 and 150 the second neighbours.
• ... and so on.
We now focus on the first neighbours which are all located between 70 and 110 pixels apart.
#We define here a data-type for each peak (called center) with 4 neighbours→˓(called north, east, south and west).point_type = np.dtype([('center_y', float), ('center_x', float),
('east_y', float), ('east_x', float),('west_y', float), ('west_x', float),('north_y', float), ('north_x', float),('south_y', float), ('south_x', float)])
neig = np.logical_and(dist>70.0, dist<110.0)valid = (neig.sum(axis=-1)==4).sum()print("There are %i control point with exactly 4 first neigbours"%valid)# This initializes an empty structure to be populatedpoint = numpy.zeros(valid, point_type)
There are 359 control point with exactly 4 first neigbours
#Populate the structure: we use a loop as it loops only over 400 pointsh=-1for i, center in enumerate(peaks_ref):
if neig[i].sum()!=4: continueh+=1point[h]["center_y"],point[h]["center_x"] = centerfor j in ((0,1),(0,-1),(1,0),(-1,0)):
tmp = []for k in numpy.where(neig[i]):
curr = yx[k]tmp.append(dot(curr-center,j))l = argmax(tmp)y, x = peaks_ref[numpy.where(neig[i])][l]if j==(0,1):point[h]["east_y"], point[h]["east_x"] = y, xelif j==(0,-1):point[h]["west_y"], point[h]["west_x"] = y, xelif j==(1,0): point[h]["north_y"],point[h]["north_x"] = y, xelif j==(-1,0):point[h]["south_y"],point[h]["south_x"] = y, x
We will need to define an origin but taking it on the border of the image is looking for trouble as this is wheredistortions are likely to be the most important. The center of the detector is an option but we prefer to take thepeak the nearest to the centroid of all other peaks.
#Select the initial guess for the center:
#Most intense peak:#m = max([i for i in regions], key=lambda i:i.maxi)#Cx, Cy = m.index%img.shape[-1],m.index//img.shape[-1]#Cx, Cy = point["center_x"].mean(), point["center_y"].mean() #Centroid of all→˓pointsCx, Cy = 734, 1181 #beam center#Cx, Cy = tuple(i//2 for i in cnv.shape) #detector centerprint("The guessed center is at (%s, %s)"%(Cx, Cy))
64 Chapter 3. Tutorials
![Page 69: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/69.jpg)
pyFAI Documentation, Release 0.15.0a0
#Get the nearest point from centroid:d2 = ((point["center_x"]-Cx)**2+(point["center_y"]-Cy)**2)best = d2.argmin()Op = point[best]Ox, Oy = Op["center_x"], Op["center_y"]
print("The center is at (%s, %s)"%(Ox, Oy))#Calculate the average vector along the 4 main axesXx = (point[:]["east_x"] - point[:]["center_x"]).mean()Xy = (point[:]["east_y"] - point[:]["center_y"]).mean()Yx = (point[:]["north_x"] - point[:]["center_x"]).mean()Yy = (point[:]["north_y"] - point[:]["center_y"]).mean()
print("The X vector is is at (%s, %s)"%(Xx, Xy))print("The Y vector is is at (%s, %s)"%(Yx, Yy))
The guessed center is at (734, 1181)The center is at (753.703500152, 1186.18798503)The X vector is is at (97.7197301826, -0.787977117653)The Y vector is is at (1.38218579497, 97.0826990758)
print("X has an angle of %s deg"%rad2deg(arctan2(Xy, Xx)))print("Y has an angle of %s deg"%rad2deg(arctan2(Yy, Yx)))print("The XY angle is %s deg"%rad2deg(arctan2(Yy, Yx)-arctan2(Xy, Xx)))
X has an angle of -0.462002756355 degY has an angle of 89.1843236418 degThe XY angle is 89.6463263982 deg
x = point[:]["center_x"] - Oxy = point[:]["center_y"] - Oyxy = numpy.vstack((x,y))R = numpy.array([[Xx,Yx],[Xy,Yy]])iR = numpy.linalg.inv(R)IJ = dot(iR,xy).T
Xmin = IJ[:,0].min()Xmax = IJ[:,0].max()Ymin = IJ[:,1].min()Ymax = IJ[:,1].max()print("Xmin/max",Xmin, Xmax)print("Ymin/max",Ymin,Ymax)print("Maximum error versus integrer: %s * pitch size (5mm)"%(abs(IJ-IJ.round()).→˓max()))
Xmin/max -6.07394212848 12.060721056Ymin/max -11.0890545732 7.04060363671Maximum error versus integrer: 0.117211354675 * pitch size (5mm)
At this point it is important to check the correct rounding to integers: The maximum error should definitely bebetter than 0.2*pitch ! If not, try to change the origin (Cx and Cy). This criteria will be used for the optimizationlater on.
fig, ax = subplots()plot(IJ[:,0],IJ[:,1],"or")idx = numpy.round(IJ).astype(int)plot(idx[:,0],IJ[:,1],"og")xlim(floor(Xmin), ceil(Xmax))ylim(floor(Ymin), ceil(Ymax))title("Red: measured peaks, Green: Expected position")
3.7. CCD calibration 65
![Page 70: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/70.jpg)
pyFAI Documentation, Release 0.15.0a0
<IPython.core.display.Javascript object>
<matplotlib.text.Text at 0x7ff38ec51668>
Estimation of the pixel size:
The pixel size is obtained from the pitch of the grid, in vectorial:
𝑝𝑖𝑡𝑐ℎ2 = (𝑃𝑥 ·𝑋𝑥)2 + (𝑃𝑦 ·𝑋𝑦)2
𝑝𝑖𝑡𝑐ℎ2 = (𝑃𝑥 · 𝑌 𝑥)2 + (𝑃𝑦 · 𝑌 𝑦)2
pitch = 5e-3 #mm distance between holesPy = pitch*sqrt((Yx**2-Xx**2)/((Xy*Yx)**2-(Xx*Yy)**2))Px = sqrt((pitch**2-(Xy*Py)**2)/Xx**2)print("Pixel size in average: x:%.3f micron, y: %.3f microns"%(Px*1e6, Py*1e6))
Pixel size in average: x:51.165 micron, y: 51.497 microns
At this stage, we have:
• A list of control points placed on a regular grid with a sub-pixel precision
• The center of the image, located on a control point
• the average X and Y vector to go from one control point to another
Optimization of the pixel position
The optimization is obtained by minimizing the mis-placement of the control points on the regular grid. For alarger coverage we include now the peaks on the border with less than 4 neighbours.
#Measured peaks (all!), needs to flip x<->ypeaks_m = numpy.empty_like(peaks_ref)peaks_m[:,1] = peaks_ref[:,0]peaks_m[:,0] = peaks_ref[:,1]
#parameter set for optimization:P0 = [Ox, Oy, Xx, Yx, Xy, Yy]
P = numpy.array(P0)
def to_hole(P, pixels):"Translate pixel -> hole"T = numpy.atleast_2d(P[:2])R = P[2:].reshape((2,2))#Transformation matrix from pixel to holes:hole = dot(numpy.linalg.inv(R), (pixels - T).T).Treturn hole
def to_pix(P, holes):"Translate hole -> pixel"T = numpy.atleast_2d(P[:2])R = P[2:].reshape((2,2))#Transformation from index points (holes) to pixel coordinates:pix = dot(R,holes.T).T + Treturn pix
def error(P):
66 Chapter 3. Tutorials
![Page 71: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/71.jpg)
pyFAI Documentation, Release 0.15.0a0
"Error function"hole_float = to_hole(P, peaks_m)hole_int = hole_float.round()delta = hole_float-hole_intdelta2 = (delta**2).sum()return delta2
print("Total inital error ", error(P), P0)holes = to_hole(P, peaks_m)print("Maximum initial error versus integrer: %s * pitch size (5mm)"%(abs(holes-→˓holes.round()).max()))from scipy.optimize import minimizeres = minimize(error, P)print(res)print("total Final error ", error(res.x),res.x)holes = to_hole(res.x, peaks_m)print("Maximum final error versus integrer: %s * pitch size (5mm)"%(abs(holes-→˓holes.round()).max()))
Total inital error 2.5995763607 [753.70350015163422, 1186.1879850327969, 97.→˓719730182623479, 1.3821857949656571, -0.78797711765336542, 97.082699075794565]Maximum initial error versus integrer: 0.199838456433 * pitch size (5mm)
fun: 2.1237728421701676hess_inv: array([[ 1.41698761e+01, 5.14376506e-01, -8.73726755e-01,
5.59794035e-01, -1.90080581e-02, 4.85640242e-02],[ 5.14376506e-01, 1.44179975e+01, -1.04326901e-02,
2.96679244e-02, -8.76422736e-01, 5.58084948e-01],[ -8.73726755e-01, -1.04326901e-02, 3.00108039e-01,-4.24894932e-03, 2.57739477e-03, -2.33763702e-03],
[ 5.59794035e-01, 2.96679244e-02, -4.24894932e-03,3.01120848e-01, -1.37978831e-03, 4.37713874e-03],
[ -1.90080581e-02, -8.76422736e-01, 2.57739477e-03,-1.37978831e-03, 2.97352626e-01, -3.79479806e-03],
[ 4.85640242e-02, 5.58084948e-01, -2.33763702e-03,4.37713874e-03, -3.79479806e-03, 2.93475780e-01]])
jac: array([ -3.87430191e-07, 2.68220901e-07, -9.53674316e-07,-4.76837158e-07, 5.66244125e-07, 9.53674316e-07])
message: 'Optimization terminated successfully.'nfev: 160nit: 15
njev: 20status: 0success: True
x: array([ 7.53021129e+02, 1.18519693e+03, 9.81143528e+01,1.47509435e+00, -8.04478826e-01, 9.73166901e+01])
total Final error 2.12377284217 [ 7.53021129e+02 1.18519693e+03 9.→˓81143528e+01 1.47509435e+00-8.04478826e-01 9.73166901e+01]
Maximum final error versus integrer: 0.234645015035 * pitch size (5mm)
fig,ax = subplots()peaks_c = to_pix(res.x,to_hole(res.x,peaks_m).round())ax.imshow(img, interpolation="nearest", origin="lower")ax.plot(peaks_m[:,0],peaks_m[:, 1], "or")ax.plot(peaks_c[:,0], peaks_c[:, 1], "og")xlim(0, 2048)ylim(0, 2048)ax.set_title("Peak position: measured (red) and expected (Green)")
<IPython.core.display.Javascript object>
3.7. CCD calibration 67
![Page 72: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/72.jpg)
pyFAI Documentation, Release 0.15.0a0
<matplotlib.text.Text at 0x7ff38ec32160>
pitch = 5e-3 #mm distance between holesOx, Oy, Xx, Yx, Xy, Yy = res.xPy = pitch*sqrt((Yx**2-Xx**2)/((Xy*Yx)**2-(Xx*Yy)**2))Px = sqrt((pitch**2-(Xy*Py)**2)/Xx**2)print("Optimized pixel size in average: x:%.3f micron, y: %.3f microns"%(Px*1e6,→˓Py*1e6))
Optimized pixel size in average: x:50.959 micron, y: 51.373 microns
Few comments:
• The maximum error grow during optimization without explanations
• The outer part of the detector is the most distorted
Interpolation of the fitted data
Multivariate data interpolation (griddata)
Correction arrays are built slightly larger (+1) to be able to manipulate corners instead of centers of pixels Ascoordinates are needed as y,x (and not x,y) we use p instead of peaks_m
from scipy.interpolate import griddatagrid_x, grid_y = np.mgrid[0:img.shape[0]+1, 0:img.shape[1]+1]delta = peaks_c - peaks_m#we use peaks_res instead of peaks_m to be in y,x coordinates, not x,ydelta_x = griddata(peaks_ref, delta[:,0], (grid_x, grid_y), method='cubic')delta_y = griddata(peaks_ref, delta[:,1], (grid_x, grid_y), method='cubic')
fig, ax = subplots(1, 2, figsize=(10,5))im0 = ax[0].imshow(delta_x,origin="lower", interpolation="nearest")ax[0].set_title(r"$\delta$ x")fig.colorbar(im0, ax=ax[0])
im1=ax[1].imshow(delta_y, origin="lower", interpolation="nearest")ax[1].set_title(r"$\delta$ y")fig.colorbar(im1, ax=ax[1])
#Nota: the arrays are filled with "NaN" outside the convex Hull
<IPython.core.display.Javascript object>
<matplotlib.colorbar.Colorbar at 0x7ff388a73978>
#From http://stackoverflow.com/questions/3662361/fill-in-missing-values-with-→˓nearest-neighbour-in-python-numpy-masked-arraysdef fill(data, invalid=None):
"""Replace the value of invalid 'data' cells (indicated by 'invalid')by the value of the nearest valid data cell
Input:data: numpy array of any dimensioninvalid: a binary array of same shape as 'data'. True cells set where data
value should be replaced.If None (default), use: invalid = np.isnan(data)
68 Chapter 3. Tutorials
![Page 73: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/73.jpg)
pyFAI Documentation, Release 0.15.0a0
Output:Return a filled array.
"""
if invalid is None:invalid = numpy.isnan(data)
ind = ndimage.distance_transform_edt(invalid, return_distances=False, return_→˓indices=True)
return data[tuple(ind)]
fig, ax = subplots(1,2, figsize=(10,5))im0 = ax[0].imshow(fill(delta_x),origin="lower", interpolation="nearest")ax[0].set_title(r"$\delta$ x")fig.colorbar(im0, ax=ax[0])
im1 = imshow(fill(delta_y), origin="lower", interpolation="nearest")title(r"$\delta$ y")fig.colorbar(im1, ax=ax[1])
<IPython.core.display.Javascript object>
<matplotlib.colorbar.Colorbar at 0x7ff38893bcf8>
It is important to understand the extrapolation outside the convex hull has no justification, it is there just to preventnumerical bugs.
Saving the distortion correction arrays to a detector
from pyFAI.detectors import Detectordetector = Detector(Py,Px)detector.max_shape = detector.shape = img.shapedetector.set_dx(fill(delta_x))detector.set_dy(fill(delta_y))detector.mask = numpy.isnan(delta_x).astype(numpy.int8)[:img.shape[0], :img.→˓shape[1]]detector.save("testdetector.h5")
Validation of the distortion correction
from pyFAI.distortion import Distortiondis = Distortion(detector)cor = dis.correct(img)
fig, ax = subplots(1, 2, figsize=(10,5))ax[0].imshow(img, interpolation="nearest", origin="lower")ax[0].set_title("Original")
ax[1].imshow(cor, origin="lower", interpolation="nearest")ax[1].set_title("Corrected")
# Save the corrected imagefabio.edfimage.EdfImage(data=cor).save("corrected.edf")
<IPython.core.display.Javascript object>
3.7. CCD calibration 69
![Page 74: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/74.jpg)
pyFAI Documentation, Release 0.15.0a0
Conclusion
This procedure describes how to measure the detector distortion and how to create a detector description filedirectly usable in pyFAI. Only the region inside the convex hull of the grid data-points is valid and the region ofthe detector which is not calibrated has been masked out to prevent accidental use of it.
The distortion corrected image can now be used to check how “good” the calibration actually is. This file can beinjected in the third cell, and follow the same procedure (left as exercise). This gives a maximum mis-placementof 0.003, the average error is then of 0.0006 and correction-map exhibit a displacement of pixels in the range +/-0.2 pixels which is acceptable and validates the whole procedure.
print("Execution time: %.3fs"%(time.time()-start_time))
Execution time: 26.104s
Goniometer and translation table calibration
Advanced tutorials on goniometer calibration in pyFAI.
Calibration of a detector on a translation table
The aim of this document is to explain how to use pyFAI.goniometer for calibrating the position detector from thetranslation table encoders.
Those data have been acquired at ESRF-ID29 in summer 2013 on a Pilatus 6M using Ceria (CeO2) as calibrant.Seven images have been acquired with the detector moved between 15 cm and 45 cm from the sample position.A prior calibration has been performed using the MX-calibrate script from the pyFAI suite. The control pointsextracted during this initial calibration have been used as a starting point for this calibration.
The raw data files are available at: http://www.silx.org/pub/pyFAI/gonio/MX-ceria/
# Initialization of the plotting library for use in the Jupyter notebook
%pylab nbagg
Populating the interactive namespace from numpy and matplotlib
# Loading of a few libraries
import timestart_time =time.time()import osimport fabioimport pyFAIfrom pyFAI.goniometer import GeometryTransformation, GoniometerRefinement,→˓Goniometerfrom pyFAI.gui import jupyter
#Download all images#Specific at ESRFos.environ["http_proxy"] = "http://proxy.esrf.fr:3128"from silx.resources import ExternalResourcesdownloader = ExternalResources("pyFAI", "http://www.silx.org/pub/pyFAI/testimages",→˓ "PYFAI_DATA")all_files = downloader.getdir("MX_ceria.tar.bz2")print(all_files)
70 Chapter 3. Tutorials
![Page 75: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/75.jpg)
pyFAI Documentation, Release 0.15.0a0
['/tmp/pyFAI_testdata_kieffer/MX_ceria', '/tmp/pyFAI_testdata_kieffer/MX_ceria/→˓ceria_300_1_0001.npt', '/tmp/pyFAI_testdata_kieffer/MX_ceria/ceria_150_1_0001.cbf→˓', '/tmp/pyFAI_testdata_kieffer/MX_ceria/ceria_200_1_0001.npt', '/tmp/pyFAI_→˓testdata_kieffer/MX_ceria/ceria_250_1_0001.cbf', '/tmp/pyFAI_testdata_kieffer/MX_→˓ceria/ceria_250_1_0001.npt', '/tmp/pyFAI_testdata_kieffer/MX_ceria/ceria_400_1_→˓0001.cbf', '/tmp/pyFAI_testdata_kieffer/MX_ceria/ceria_400_1_0001.npt', '/tmp/→˓pyFAI_testdata_kieffer/MX_ceria/ceria_450_1_0001.cbf', '/tmp/pyFAI_testdata_→˓kieffer/MX_ceria/ceria_150_1_0001.poni', '/tmp/pyFAI_testdata_kieffer/MX_ceria/→˓ceria_150_1_0001.npt', '/tmp/pyFAI_testdata_kieffer/MX_ceria/ceria_200_1_0001.→˓poni', '/tmp/pyFAI_testdata_kieffer/MX_ceria/ceria_350_1_0001.poni', '/tmp/pyFAI_→˓testdata_kieffer/MX_ceria/ceria_300_1_0001.cbf', '/tmp/pyFAI_testdata_kieffer/MX_→˓ceria/ceria_450_1_0001.npt', '/tmp/pyFAI_testdata_kieffer/MX_ceria/ceria_250_1_→˓0001.poni', '/tmp/pyFAI_testdata_kieffer/MX_ceria/ceria_350_1_0001.cbf', '/tmp/→˓pyFAI_testdata_kieffer/MX_ceria/ceria_350_1_0001.npt', '/tmp/pyFAI_testdata_→˓kieffer/MX_ceria/ceria_400_1_0001.poni', '/tmp/pyFAI_testdata_kieffer/MX_ceria/→˓ceria_450_1_0001.poni', '/tmp/pyFAI_testdata_kieffer/MX_ceria/ceria_200_1_0001.→˓cbf', '/tmp/pyFAI_testdata_kieffer/MX_ceria/ceria_300_1_0001.poni']
# Loading of the list of files, and display of the first one with its headers
image_files = [i for i in all_files if i.endswith(".cbf")]image_files.sort()print("List of images: " + ", ".join(image_files) + "." + os.linesep)fimg = fabio.open(image_files[0])
print("Image headers:")for key, value in fimg.header.items():
print("%s: %s"%(key,value))
jupyter.display(fimg.data, label=os.path.basename(fimg.filename))
List of images: /tmp/pyFAI_testdata_kieffer/MX_ceria/ceria_150_1_0001.cbf, /tmp/→˓pyFAI_testdata_kieffer/MX_ceria/ceria_200_1_0001.cbf, /tmp/pyFAI_testdata_→˓kieffer/MX_ceria/ceria_250_1_0001.cbf, /tmp/pyFAI_testdata_kieffer/MX_ceria/→˓ceria_300_1_0001.cbf, /tmp/pyFAI_testdata_kieffer/MX_ceria/ceria_350_1_0001.cbf,→˓/tmp/pyFAI_testdata_kieffer/MX_ceria/ceria_400_1_0001.cbf, /tmp/pyFAI_testdata_→˓kieffer/MX_ceria/ceria_450_1_0001.cbf.
Image headers:_array_data.header_contents: # Detector: PILATUS 6M, S/N 60-0104, ESRF ID29# 2013/Aug/29 17:26:59.699# Pixel_size 172e-6 m x 172e-6 m# Silicon sensor, thickness 0.000320 m# Start_angle 0.000000 deg.# Exposure_time 0.037000 s# Exposure_period 0.040000 s# Tau = 0 s# Count_cutoff 1048500# Threshold_setting 7612 eV# N_excluded_pixels = 321# Excluded_pixels: badpix_mask.tif# Flat_field: (nil)# Trim_directory: (nil)# Wavelength 0.972386 A# Detector_distance 0.150000 m# Energy_range (0, 0) eV# Detector_Voffset 0.0000 m# Beam_xy (1230.90, 1254.09) pixels# Flux 2.823146e+11 ph/s# Transmission 20.1173# Angle_increment 1.0000 deg.# Detector_2theta 0.0000 deg.
3.8. Goniometer and translation table calibration 71
![Page 76: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/76.jpg)
pyFAI Documentation, Release 0.15.0a0
# Polarization 0.99# Alpha 0.0000 deg.# Kappa 0.0020 deg.# Phi 0.0000 deg.# Chi 0.0000 deg.# Oscillation_axis omega# N_oscillations 1# file_commentsContent-Type: application/octet-stream;conversions: x-CBF_BYTE_OFFSETContent-Transfer-Encoding: BINARYX-Binary-Size: 6262451X-Binary-ID: 0X-Binary-Element-Type: signed 32-bit integerX-Binary-Element-Byte-Order: LITTLE_ENDIANContent-MD5: BIfsFrKJBFklJn97/hjO/A==X-Binary-Number-of-Elements: 6224001X-Binary-Size-Fastest-Dimension: 2463X-Binary-Size-Second-Dimension: 2527X-Binary-Size-Padding: 128
<IPython.core.display.Javascript object>
<matplotlib.axes._subplots.AxesSubplot at 0x7f855ed419e8>
# Definition of the geometry translation function:
geotrans = GeometryTransformation(param_names = ["dist_offset", "dist_scale","poni1", "poni2", "rot1","rot2"],
dist_expr="pos * dist_scale + dist_offset",poni1_expr="poni1",poni2_expr="poni2",rot1_expr="rot1",rot2_expr="rot2",rot3_expr="0.0")
# Definition of the function reading the detector position from the header of the→˓image.
def get_distance(header):"""Takes the header of the CBF-file and returns the distance of the detector"""dist = 0for line in header.get("_array_data.header_contents","").split("\n"):
words = line.split()if words[1] == "Detector_distance":
dist = float(words[2])break
return dist
print("Distance:",get_distance(fimg.header))
Distance: 0.15
# Definition of the detector, the calibrant and extraction of the wavelength used→˓from the headers
pilatus = pyFAI.detector_factory("Pilatus6M")CeO2 = pyFAI.calibrant.get_calibrant("CeO2")for line in fimg.header.get("_array_data.header_contents","").split("\n"):
words = line.split()
72 Chapter 3. Tutorials
![Page 77: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/77.jpg)
pyFAI Documentation, Release 0.15.0a0
if words[1] == "Wavelength":wavelength = float(words[2])*1e-10break
print("Wavelength:", wavelength)CeO2.wavelength = wavelengthprint(CeO2)
Wavelength: 9.72386e-11CeO2 Calibrant at wavelength 9.72386e-11
# Definition of the geometry refinement: the parameter order is the same as the→˓param_names
param = {"dist_offset":0,"dist_scale":1,"poni1":0.2,"poni2":0.2,"rot1":0,"rot2":0}
gonioref = GoniometerRefinement(param, #initial guesspos_function=get_distance,trans_function=geotrans,detector=pilatus,wavelength=wavelength)
print("Empty refinement object:")print(gonioref)
Empty refinement object:GoniometerRefinement with 0 geometries labeled: .
# Let's populate the goniometer refinement object with all control point files:
ponis = [i for i in all_files if i.endswith(".poni")]ponis.sort()print(ponis)for fn in ponis:
base = os.path.splitext(fn)[0]fimg = fabio.open(base + ".cbf")gonioref.new_geometry(os.path.basename(base), image=fimg.data, metadata=fimg.
→˓header, control_points=base+".npt",geometry=fn, calibrant=CeO2)
print("Filled refinement object:")print(gonioref)print(os.linesep+"\tLabel \t Distance")for k, v in gonioref.single_geometries.items():
print(k,v.get_position())
['/tmp/pyFAI_testdata_kieffer/MX_ceria/ceria_150_1_0001.poni', '/tmp/pyFAI_→˓testdata_kieffer/MX_ceria/ceria_200_1_0001.poni', '/tmp/pyFAI_testdata_kieffer/→˓MX_ceria/ceria_250_1_0001.poni', '/tmp/pyFAI_testdata_kieffer/MX_ceria/ceria_300_→˓1_0001.poni', '/tmp/pyFAI_testdata_kieffer/MX_ceria/ceria_350_1_0001.poni', '/→˓tmp/pyFAI_testdata_kieffer/MX_ceria/ceria_400_1_0001.poni', '/tmp/pyFAI_testdata_→˓kieffer/MX_ceria/ceria_450_1_0001.poni']Filled refinement object:GoniometerRefinement with 7 geometries labeled: ceria_150_1_0001, ceria_200_1_0001,→˓ ceria_250_1_0001, ceria_300_1_0001, ceria_350_1_0001, ceria_400_1_0001, ceria_→˓450_1_0001.
Label Distance
3.8. Goniometer and translation table calibration 73
![Page 78: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/78.jpg)
pyFAI Documentation, Release 0.15.0a0
ceria_150_1_0001 0.15ceria_200_1_0001 0.2ceria_250_1_0001 0.25ceria_300_1_0001 0.3ceria_350_1_0001 0.35ceria_400_1_0001 0.4ceria_450_1_0001 0.45
# Display all images with associated calibration:
for sg in gonioref.single_geometries.values():jupyter.display(sg=sg)
<IPython.core.display.Javascript object>
<IPython.core.display.Javascript object>
<IPython.core.display.Javascript object>
<IPython.core.display.Javascript object>
<IPython.core.display.Javascript object>
<IPython.core.display.Javascript object>
<IPython.core.display.Javascript object>
# Initial refinement of the translation table model
gonioref.refine2()
Cost function before refinement: 0.00166968476865fun: 5.119380332306429e-07jac: array([ 1.15391165e-06, 3.42232646e-07, 8.12183671e-08,
5.02958173e-08, -7.17337869e-08, -1.11380615e-07])message: 'Optimization terminated successfully.'
nfev: 148nit: 18
njev: 18status: 0
success: Truex: array([-0.00118793, 1.00190471, 0.21548514, 0.21309905, 0.00661241,0.00280329])
Cost function after refinement: 5.119380332306429e-07GonioParam(dist_offset=-0.0011879346142064896, dist_scale=1.0019047068993876,→˓poni1=0.21548513632380822, poni2=0.21309905129447423, rot1=0.0066124085461557701,→˓ rot2=0.0028032884844600525)maxdelta on: poni1 (2) 0.2 --> 0.215485136324
array([-0.00118793, 1.00190471, 0.21548514, 0.21309905, 0.00661241,0.00280329])
# Save the result of the fitting to a file and display the content of the JSON→˓file:
gonioref.save("ID29.json")with open("ID29.json") as fd:
print(fd.read())
74 Chapter 3. Tutorials
![Page 79: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/79.jpg)
pyFAI Documentation, Release 0.15.0a0
{"content": "Goniometer calibration v1.0","detector": "Pilatus 6M","pixel1": 0.000172,"pixel2": 0.000172,"wavelength": 9.72386e-11,"param": [-0.0011879346142064896,1.0019047068993876,0.21548513632380822,0.21309905129447423,0.00661240854615577,0.0028032884844600525
],"param_names": ["dist_offset","dist_scale","poni1","poni2","rot1","rot2"
],"pos_names": ["pos"
],"trans_function": {"content": "GeometryTransformation","param_names": [
"dist_offset","dist_scale","poni1","poni2","rot1","rot2"
],"pos_names": [
"pos"],"dist_expr": "pos * dist_scale + dist_offset","poni1_expr": "poni1","poni2_expr": "poni2","rot1_expr": "rot1","rot2_expr": "rot2","rot3_expr": "0.0","constants": {
"pi": 3.141592653589793}
}}
# Restore the translation table setting from the file
transtable = Goniometer.sload("ID29.json")print("Translation table: \n",transtable)
Translation table:Goniometer with param GonioParam(dist_offset=-0.0011879346142064896, dist_scale=1.→˓0019047068993876, poni1=0.21548513632380822, poni2=0.21309905129447423, rot1=0.→˓00661240854615577, rot2=0.0028032884844600525)with Detector Pilatus 6M PixelSize= 1.720e-04, 1.720e-04 m
3.8. Goniometer and translation table calibration 75
![Page 80: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/80.jpg)
pyFAI Documentation, Release 0.15.0a0
# Create a multi-geometry object for all images in this set:
distances = [get_distance(fabio.open(fn).header) for fn in image_files]print("Distances: ", distances)multigeo = transtable.get_mg(distances)multigeo.radial_range=(0, 65)print(multigeo)
Distances: [0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45]MultiGeometry integrator with 7 geometries on (0, 65) radial range (2th_deg) and (-→˓180, 180) azimuthal range (deg)
# Integrate the set of images in a single run:
res = multigeo.integrate1d([fabio.open(fn).data for fn in image_files], 10000)
# Display the result using matplotlibfig, ax = subplots()ax.plot(*res)ax.set_xlabel(res.unit.label)ax.set_ylabel("Intensity")ax.set_xlim(17, 22)ax.set_title("Zoom on the two first rings")
<IPython.core.display.Javascript object>
<matplotlib.text.Text at 0x7f8513fc2160>
Accoring to the provious image, peaks look double which indicates a bad modeling of the setup or a bad fitting.As the fitting ended successfully, the bug is likely in the model: let’s allow the PONI to move with the distance
# Let's refine poni1 and poni2 also as function of the distance:
geotrans2 = GeometryTransformation(param_names = ["dist_offset", "dist_scale","poni1_offset", "poni1_scale","poni2_offset", "poni2_scale","rot1","rot2"],
dist_expr="pos * dist_scale + dist_offset",poni1_expr="pos * poni1_scale + poni1_offset",poni2_expr="pos * poni2_scale + poni2_offset",rot1_expr="rot1",rot2_expr="rot2",rot3_expr="0.0")
#initial guess from former parameter setparam2 = (gonioref.nt_param(*gonioref.param))._asdict()param2["poni1_offset"] = 0param2["poni2_offset"] = 0param2["poni1_scale"] = 1param2["poni2_scale"] = 1
gonioref2 = GoniometerRefinement(param2,pos_function = get_distance,trans_function=geotrans2,detector=pilatus,wavelength=wavelength)
gonioref2.single_geometries = gonioref.single_geometries.copy()print(gonioref2)
76 Chapter 3. Tutorials
![Page 81: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/81.jpg)
pyFAI Documentation, Release 0.15.0a0
GoniometerRefinement with 7 geometries labeled: ceria_150_1_0001, ceria_200_1_0001,→˓ ceria_250_1_0001, ceria_300_1_0001, ceria_350_1_0001, ceria_400_1_0001, ceria_→˓450_1_0001.
# Refinement of the second model with all distances free
gonioref2.refine2()
Cost function before refinement: 0.0436448742052fun: 1.621998573406867e-07jac: array([ 5.32202929e-07, 8.74258230e-08, 1.65541298e-07,
1.80205095e-08, -2.92970160e-07, -7.38347143e-08,8.45047090e-08, -1.73614865e-08])
message: 'Optimization terminated successfully.'nfev: 344nit: 34
njev: 34status: 0
success: Truex: array([-0.00118686, 1.00184287, 0.21574533, -0.00429667, 0.21300993,0.00138094, 0.00735187, 0.00492121])
Cost function after refinement: 1.621998573406867e-07GonioParam(dist_offset=-0.0011868649111587623, dist_scale=1.001842873704045, poni1_→˓offset=0.21574533062964613, poni1_scale=-0.0042966738927481124, poni2_offset=0.→˓21300993413748515, poni2_scale=0.0013809412109975984, rot1=0.0073518675577171084,→˓ rot2=0.0049212066470728684)maxdelta on: poni1_scale (3) 1 --> -0.00429667389275
array([-0.00118686, 1.00184287, 0.21574533, -0.00429667, 0.21300993,0.00138094, 0.00735187, 0.00492121])
# Integration of all images with the second model
multigeo2 = gonioref2.get_mg(distances)multigeo2.radial_range=(0, 65)print(multigeo2)res2 = multigeo2.integrate1d([fabio.open(fn).data for fn in image_files], 10000)
# Display the result, zooming on the two first ringsfig, ax = subplots()ax.plot(*res)ax.plot(*res, label="only distance free")ax.plot(*res2, label="distance and PONI free")ax.set_ylabel("Intensity")ax.set_xlim(17, 22)ax.set_title("Zoom on the two first rings")ax.set_xlabel(res2.unit.label)ax.legend()
MultiGeometry integrator with 7 geometries on (0, 65) radial range (2th_deg) and (-→˓180, 180) azimuthal range (deg)
<IPython.core.display.Javascript object>
<matplotlib.legend.Legend at 0x7f8513f51898>
# Re-extract many more control points from images for a better fit
for sg in gonioref2.single_geometries.values():
3.8. Goniometer and translation table calibration 77
![Page 82: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/82.jpg)
pyFAI Documentation, Release 0.15.0a0
sg.extract_cp(pts_per_deg=3)jupyter.display(sg=sg)
<IPython.core.display.Javascript object>
<IPython.core.display.Javascript object>
<IPython.core.display.Javascript object>
<IPython.core.display.Javascript object>
<IPython.core.display.Javascript object>
<IPython.core.display.Javascript object>
<IPython.core.display.Javascript object>
# Refine again the model
gonioref2.refine2()
# Build the MultiGeometry integrator object
multigeo3 = gonioref2.get_mg(distances)multigeo3.radial_range=(0, 65)print(multigeo3)
# Perform the azimuthal integrationres3 = multigeo3.integrate1d([fabio.open(fn).data for fn in image_files], 10000)
# Display the resultfig, ax = subplots()ax.plot(*res, label="only distance free")ax.plot(*res2, label="distance and PONI free")ax.plot(*res2, linestyle="--", label="distance and PONI free, more points")ax.set_xlabel(res2.unit.label)ax.set_xlim(17, 22)ax.legend()
Cost function before refinement: 5.44056328167e-08fun: 5.0566147640240304e-08jac: array([ -2.72988081e-08, -9.85080661e-08, 8.53232200e-08,
1.48880348e-07, -6.61621531e-07, -2.73877250e-08,6.89865807e-07, -3.24930589e-07])
message: 'Optimization terminated successfully.'nfev: 113nit: 11
njev: 11status: 0
success: Truex: array([-0.00120798, 1.00182259, 0.21574481, -0.00410325, 0.21301486,0.00124889, 0.00726767, 0.00480277])
Cost function after refinement: 5.0566147640240304e-08GonioParam(dist_offset=-0.0012079755055219347, dist_scale=1.0018225861866563,→˓poni1_offset=0.21574480896327708, poni1_scale=-0.0041032454096946308, poni2_→˓offset=0.21301485782424609, poni2_scale=0.0012488853665311719, rot1=0.→˓0072676696888075145, rot2=0.0048027715788010314)maxdelta on: poni1_scale (3) -0.00429667389275 --> -0.00410324540969MultiGeometry integrator with 7 geometries on (0, 65) radial range (2th_deg) and (-→˓180, 180) azimuthal range (deg)
78 Chapter 3. Tutorials
![Page 83: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/83.jpg)
pyFAI Documentation, Release 0.15.0a0
<IPython.core.display.Javascript object>
<matplotlib.legend.Legend at 0x7f850c5a76d8>
This re-extraction of control point did not help to get a sharper diffraction profile. This step was un-necessary.
Conclusion
This notebook exposes the how to calibrate a translation table for a moving detector. It allows to: * Check theproper alignement of the table regarding the actual beam * Check the encoder’s precision (usually good) andoffsets (arbitrary) * Perform azimuthal integration to retrieve powder diffraction patterns at any position of thedetector.
print("Total execution time: %.3fs"%(time.time() - start_time))
Total execution time: 267.747s
Calibration of a 2 theta arm with a Pilatus 100k detector
The aim of this document is to explain how to use pyFAI.goniometer for calibrating the position of the detectorfrom the goniometer encoders.
Those data have been acquired at ROBL (ESRF-BM20 German CRG) in winter 2017 by Christoph Henning usinga Pilatus 100k detector and LaB6 as calibrant. One hundred and twenty one images have been acquired with thedetector moving between 5 and 65 degree with a step size of half a degree. The motor position is registered in thefilename.
A prior manual calibration (using pyFAI-calib) has been performed on four images locate at 31.5, 33.5, 35 and35.5 degrees. Those images were the first with two rings. The control points extrated during this initial calibrationhas been used as a starting point for this calibration. Then more images have been added to make the model morerobust.
The raw data files are available at: http://www.silx.org/pub/pyFAI/gonio/Pilatus-100k-LaB6/
Initialization and loading of the libraries
Initialization of the plotting library, matplotlib, to be used with the jupyter notebook
%pylab nbagg
import timestart_time = time.time()
Populating the interactive namespace from numpy and matplotlib
#Download all images
import osfrom silx.resources import ExternalResources
#Specific for ESRFos.environ["http_proxy"] = "http://proxy.esrf.fr:3128"
downloader = ExternalResources("pyFAI", "http://www.silx.org/pub/pyFAI/testimages",→˓ "PYFAI_DATA")
3.8. Goniometer and translation table calibration 79
![Page 84: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/84.jpg)
pyFAI Documentation, Release 0.15.0a0
all_files = downloader.getdir("LaB6_gonio_BM20.tar.bz2")print(all_files)
['/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20', '/tmp/pyFAI_testdata_kieffer/LaB6_→˓gonio_BM20/del_45.0_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_→˓08.5_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_20.5_0001p.cbf→˓', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/minimum-mask.edf', '/tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_09.0_0001p.cbf', '/tmp/pyFAI_testdata_→˓kieffer/LaB6_gonio_BM20/del_53.0_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_→˓gonio_BM20/del_60.0_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_→˓63.5_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_56.5_0001p.cbf→˓', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_12.5_0001p.cbf', '/tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_53.5_0001p.cbf', '/tmp/pyFAI_testdata_→˓kieffer/LaB6_gonio_BM20/del_42.5_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_→˓gonio_BM20/del_16.5_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_→˓05.5_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_47.0_0001p.cbf→˓', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_39.0_0001p.cbf', '/tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_47.5_0001p.cbf', '/tmp/pyFAI_testdata_→˓kieffer/LaB6_gonio_BM20/del_57.0_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_→˓gonio_BM20/del_35.5_0001p.poni', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/→˓del_07.5_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_41.5_0001p.→˓cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_51.0_0001p.cbf', '/tmp/→˓pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_33.0_0001p.cbf', '/tmp/pyFAI_testdata_→˓kieffer/LaB6_gonio_BM20/del_22.0_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_→˓gonio_BM20/del_43.5_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_→˓64.5_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_35.0_0001p.cbf→˓', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_13.5_0001p.cbf', '/tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_08.0_0001p.cbf', '/tmp/pyFAI_testdata_→˓kieffer/LaB6_gonio_BM20/del_29.0_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_→˓gonio_BM20/del_45.5_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_→˓63.0_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_61.5_0001p.cbf→˓', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_31.5_0001p.npt', '/tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_11.0_0001p.cbf', '/tmp/pyFAI_testdata_→˓kieffer/LaB6_gonio_BM20/del_46.5_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_→˓gonio_BM20/del_11.5_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_→˓56.0_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_18.0_0001p.cbf→˓', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_06.5_0001p.cbf', '/tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_46.0_0001p.cbf', '/tmp/pyFAI_testdata_→˓kieffer/LaB6_gonio_BM20/del_58.5_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_→˓gonio_BM20/del_35.5_0001p.npt', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_→˓30.0_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_15.5_0001p.cbf→˓', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_36.5_0001p.cbf', '/tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_13.0_0001p.cbf', '/tmp/pyFAI_testdata_→˓kieffer/LaB6_gonio_BM20/del_55.0_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_→˓gonio_BM20/del_27.5_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_→˓31.5_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_24.0_0001p.cbf→˓', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_38.0_0001p.cbf', '/tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_48.5_0001p.cbf', '/tmp/pyFAI_testdata_→˓kieffer/LaB6_gonio_BM20/del_16.0_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_→˓gonio_BM20/del_52.5_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_→˓38.5_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_54.5_0001p.cbf→˓', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_48.0_0001p.cbf', '/tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_31.0_0001p.cbf', '/tmp/pyFAI_testdata_→˓kieffer/LaB6_gonio_BM20/del_28.5_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_→˓gonio_BM20/del_21.5_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_→˓06.0_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_25.5_0001p.cbf→˓', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_40.5_0001p.cbf', '/tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_44.5_0001p.cbf', '/tmp/pyFAI_testdata_→˓kieffer/LaB6_gonio_BM20/del_39.5_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_→˓gonio_BM20/del_35.5_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_→˓62.0_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_36.0_0001p.cbf→˓', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_57.5_0001p.cbf', '/tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_28.0_0001p.cbf', '/tmp/pyFAI_testdata_→˓kieffer/LaB6_gonio_BM20/del_17.5_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_→˓gonio_BM20/del_24.5_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_→˓35.0_0001p.poni', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_50.5_0001p.cbf→˓', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_18.5_0001p.cbf', '/tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_27.0_0001p.cbf', '/tmp/pyFAI_testdata_→˓kieffer/LaB6_gonio_BM20/del_19.5_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_→˓gonio_BM20/del_21.0_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_→˓17.0_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_50.0_0001p.cbf→˓', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_44.0_0001p.cbf', '/tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_30.5_0001p.cbf', '/tmp/pyFAI_testdata_→˓kieffer/LaB6_gonio_BM20/del_51.5_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_→˓gonio_BM20/del_62.5_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_→˓05.0_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_26.5_0001p.cbf→˓', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_31.5_0001p.poni', '/tmp/→˓pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_23.5_0001p.cbf', '/tmp/pyFAI_testdata_→˓kieffer/LaB6_gonio_BM20/del_33.5_0001p.poni', '/tmp/pyFAI_testdata_kieffer/LaB6_→˓gonio_BM20/del_37.5_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_→˓19.0_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_29.5_0001p.cbf→˓', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_10.0_0001p.cbf', '/tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_40.0_0001p.cbf', '/tmp/pyFAI_testdata_→˓kieffer/LaB6_gonio_BM20/del_58.0_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_→˓gonio_BM20/del_49.5_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_→˓09.5_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_15.0_0001p.cbf→˓', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_43.0_0001p.cbf', '/tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_60.5_0001p.cbf', '/tmp/pyFAI_testdata_→˓kieffer/LaB6_gonio_BM20/del_34.0_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_→˓gonio_BM20/del_20.0_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/→˓deviation-mask.edf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_41.0_0001p.→˓cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_07.0_0001p.cbf', '/tmp/→˓pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_54.0_0001p.cbf', '/tmp/pyFAI_testdata_→˓kieffer/LaB6_gonio_BM20/del_33.5_0001p.npt', '/tmp/pyFAI_testdata_kieffer/LaB6_→˓gonio_BM20/del_33.5_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_→˓32.0_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_59.5_0001p.cbf→˓', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_14.0_0001p.cbf', '/tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_32.5_0001p.cbf', '/tmp/pyFAI_testdata_→˓kieffer/LaB6_gonio_BM20/del_59.0_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_→˓gonio_BM20/del_65.0_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_→˓25.0_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_61.0_0001p.cbf→˓', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_34.5_0001p.cbf', '/tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_52.0_0001p.cbf', '/tmp/pyFAI_testdata_→˓kieffer/LaB6_gonio_BM20/del_22.5_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_→˓gonio_BM20/del_10.5_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_→˓42.0_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_64.0_0001p.cbf→˓', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_14.5_0001p.cbf', '/tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_26.0_0001p.cbf', '/tmp/pyFAI_testdata_→˓kieffer/LaB6_gonio_BM20/del_49.0_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_→˓gonio_BM20/del_35.0_0001p.npt', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_→˓55.5_0001p.cbf', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_23.0_0001p.cbf→˓', '/tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_12.0_0001p.cbf', '/tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_37.0_0001p.cbf']
80 Chapter 3. Tutorials
![Page 85: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/85.jpg)
pyFAI Documentation, Release 0.15.0a0
#Loading of a few libraries
import osimport randomimport fabioimport pyFAIfrom pyFAI.goniometer import GeometryTransformation, GoniometerRefinement,→˓Goniometerfrom pyFAI.gui import jupyter
Display of an image and its headers
#loading of the list of files, and display of the last one with its headers
image_files = [i for i in all_files if i.endswith(".cbf")]image_files.sort()print("List of images: " + ", ".join(image_files) + "." + os.linesep)fimg = fabio.open(image_files[-1])
print("Image headers:")for key, value in fimg.header.items():
print("%s: %s"%(key,value))
jupyter.display(fimg.data, label=os.path.basename(fimg.filename))
List of images: /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_05.0_0001p.cbf, /→˓tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_05.5_0001p.cbf, /tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_06.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/→˓LaB6_gonio_BM20/del_06.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/→˓del_07.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_07.5_0001p.→˓cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_08.0_0001p.cbf, /tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_08.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/→˓LaB6_gonio_BM20/del_09.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/→˓del_09.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_10.0_0001p.→˓cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_10.5_0001p.cbf, /tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_11.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/→˓LaB6_gonio_BM20/del_11.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/→˓del_12.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_12.5_0001p.→˓cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_13.0_0001p.cbf, /tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_13.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/→˓LaB6_gonio_BM20/del_14.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/→˓del_14.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_15.0_0001p.→˓cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_15.5_0001p.cbf, /tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_16.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/→˓LaB6_gonio_BM20/del_16.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/→˓del_17.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_17.5_0001p.→˓cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_18.0_0001p.cbf, /tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_18.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/→˓LaB6_gonio_BM20/del_19.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/→˓del_19.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_20.0_0001p.→˓cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_20.5_0001p.cbf, /tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_21.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/→˓LaB6_gonio_BM20/del_21.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/→˓del_22.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_22.5_0001p.→˓cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_23.0_0001p.cbf, /tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_23.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/→˓LaB6_gonio_BM20/del_24.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/→˓del_24.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_25.0_0001p.→˓cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_25.5_0001p.cbf, /tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_26.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/→˓LaB6_gonio_BM20/del_26.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/→˓del_27.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_27.5_0001p.→˓cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_28.0_0001p.cbf, /tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_28.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/→˓LaB6_gonio_BM20/del_29.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/→˓del_29.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_30.0_0001p.→˓cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_30.5_0001p.cbf, /tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_31.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/→˓LaB6_gonio_BM20/del_31.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/→˓del_32.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_32.5_0001p.→˓cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_33.0_0001p.cbf, /tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_33.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/→˓LaB6_gonio_BM20/del_34.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/→˓del_34.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_35.0_0001p.→˓cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_35.5_0001p.cbf, /tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_36.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/→˓LaB6_gonio_BM20/del_36.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/→˓del_37.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_37.5_0001p.→˓cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_38.0_0001p.cbf, /tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_38.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/→˓LaB6_gonio_BM20/del_39.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/→˓del_39.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_40.0_0001p.→˓cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_40.5_0001p.cbf, /tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_41.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/→˓LaB6_gonio_BM20/del_41.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/→˓del_42.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_42.5_0001p.→˓cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_43.0_0001p.cbf, /tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_43.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/→˓LaB6_gonio_BM20/del_44.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/→˓del_44.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_45.0_0001p.→˓cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_45.5_0001p.cbf, /tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_46.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/→˓LaB6_gonio_BM20/del_46.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/→˓del_47.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_47.5_0001p.→˓cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_48.0_0001p.cbf, /tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_48.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/→˓LaB6_gonio_BM20/del_49.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/→˓del_49.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_50.0_0001p.→˓cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_50.5_0001p.cbf, /tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_51.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/→˓LaB6_gonio_BM20/del_51.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/→˓del_52.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_52.5_0001p.→˓cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_53.0_0001p.cbf, /tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_53.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/→˓LaB6_gonio_BM20/del_54.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/→˓del_54.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_55.0_0001p.→˓cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_55.5_0001p.cbf, /tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_56.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/→˓LaB6_gonio_BM20/del_56.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/→˓del_57.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_57.5_0001p.→˓cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_58.0_0001p.cbf, /tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_58.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/→˓LaB6_gonio_BM20/del_59.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/→˓del_59.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_60.0_0001p.→˓cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_60.5_0001p.cbf, /tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_61.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/→˓LaB6_gonio_BM20/del_61.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/→˓del_62.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_62.5_0001p.→˓cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_63.0_0001p.cbf, /tmp/pyFAI_→˓testdata_kieffer/LaB6_gonio_BM20/del_63.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/→˓LaB6_gonio_BM20/del_64.0_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/→˓del_64.5_0001p.cbf, /tmp/pyFAI_testdata_kieffer/LaB6_gonio_BM20/del_65.0_0001p.→˓cbf.
3.8. Goniometer and translation table calibration 81
![Page 86: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/86.jpg)
pyFAI Documentation, Release 0.15.0a0
Image headers:_array_data.header_convention: PILATUS_1.2_array_data.header_contents: # Detector: PILATUS 2M, 24-0111# 2016-05-17T18:12:57.232113# Pixel_size 172e-6 m x 172e-6 m# Silicon sensor, thickness 0.000450 m# Exposure_time 9.9977 s# Exposure_period 9.9977 s# Tau = 1.991e-07 s# Count_cutoff 1071182 counts# Threshold_setting: 4024.0 eV# Gain_setting: low gain (vrf = -0.300)# N_excluded_pixels = 1# Excluded_pixels: badpix_mask.tif# Flat_field: FF_p2m0111_E26000_T13000_vrf_m0p30.tif# Trim_file: p2m0111_E26000_T13000_vrf_m0p30.bin# Image_path: /ramdisk/# Wavelength 0.7749 A# Start_angle 0.00 deg.# Angle_increment 0.00 deg.# Omega 0.00 deg.# Omega_increment 0.00 deg.# Phi 0.00 deg.# Phi_increment 0.00 deg.# Kappa 0.0 deg.# Oscillation_axis PHI# Detector_distance 0.157 m# Detector_Voffset 0.0 m# Beam_xy (542.41, 732.4) pixels# Flux 0 counts# Temperature 0.00 K# Blower 0.0 C# Lakeshore 0.00 KContent-Type: application/octet-stream;conversions: x-CBF_BYTE_OFFSETContent-Transfer-Encoding: BINARYX-Binary-Size: 95035X-Binary-ID: 1X-Binary-Element-Type: signed 32-bit integerX-Binary-Element-Byte-Order: LITTLE_ENDIANContent-MD5: darooj/7FEQRNdNzNDo0XQ==X-Binary-Number-of-Elements: 94965X-Binary-Size-Fastest-Dimension: 487X-Binary-Size-Second-Dimension: 195X-Binary-Size-Padding: 4095
<IPython.core.display.Javascript object>
<matplotlib.axes._subplots.AxesSubplot at 0x7ffb27d85a90>
Definition of the geometry transformation
This is the most difficult part to understand.
The next cell defines 2 functions, one for transforming the geometry and the other one to read the goniometerangle from the metadata
#Definition of the goniometer translation function:# The detector rotates vertically, around the horizontal axis, i.e. rot2
82 Chapter 3. Tutorials
![Page 87: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/87.jpg)
pyFAI Documentation, Release 0.15.0a0
goniotrans = GeometryTransformation(param_names = ["dist", "poni1", "poni2", "rot1→˓",
"rot2_offset", "rot2_scale"],dist_expr="dist",poni1_expr="poni1",poni2_expr="poni2",rot1_expr="rot1",rot2_expr="rot2_scale * pos + rot2_offset",rot3_expr="0.0")
#Definition of the function reading the goniometer angle from the filename of the→˓image.
def get_angle(basename):"""Takes the basename (like del_65.0_0001p ) and returns the angle of the
→˓detector"""return float(os.path.basename((basename.split("_")[1])))
basename = os.path.basename(fimg.filename)print('filename', basename, "angle:",get_angle(basename))
filename del_65.0_0001p.cbf angle: 65.0
#Definition of the detector, its mask, the calibrantmask_files = [i for i in all_files if i.endswith("-mask.edf")]mask = numpy.logical_or(fabio.open(mask_files[0]).data, fabio.open(mask_files[1]).→˓data)pilatus = pyFAI.detector_factory("Pilatus100k")pilatus.mask = mask
LaB6 = pyFAI.calibrant.CALIBRANT_FACTORY("LaB6")wavelength = 7.7490120575e-11LaB6.wavelength = wavelength
#Definition of the geometry refinement: the parameter order is the same as the→˓param_names
param = {"dist":0.8,"poni1":0.02,"poni2":0.04,"rot1":0,"rot2_offset":0,"rot2_scale": numpy.pi/180. # rot2 is in radians, while the motor
→˓position is in degrees}
#Defines the bounds for some variablesbounds = {"dist": (0.79, 0.81),
"rot1": (-0.01, 0.01),"rot2_offset": (-0.01, 0.01),"rot2_scale": (numpy.pi/180., numpy.pi/180.) #strict bounds on the
→˓scale: we expect the gonio to be precise}
gonioref = GoniometerRefinement(param, #initial guessbounds=bounds,pos_function=get_angle,trans_function=goniotrans,detector=pilatus, wavelength=wavelength)
print("Empty refinement object:")print(gonioref)
3.8. Goniometer and translation table calibration 83
![Page 88: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/88.jpg)
pyFAI Documentation, Release 0.15.0a0
Empty refinement object:GoniometerRefinement with 0 geometries labeled: .
#Let's populate the goniometer refinement object with all control point files:
ponis = [i for i in all_files if i.endswith(".poni")]ponis.sort()for fn in ponis:
base = os.path.splitext(fn)[0]basename = os.path.basename(base)fimg = fabio.open(base + ".cbf")sg =gonioref.new_geometry(basename, image=fimg.data, metadata=basename,
→˓control_points=base+".npt",geometry=fn, calibrant=LaB6)
print(sg.label, "Angle:", sg.get_position())print(sg.geometry_refinement)print()
print("Filled refinement object:")print(gonioref)
del_31.5_0001p Angle: 31.5Detector Pilatus 100k PixelSize= 1.720e-04, 1.720e-04 mWavelength= 7.749012e-11mSampleDetDist= 8.058209e-01m PONI= 5.700310e-03, 4.599931e-02m rot1=-→˓0.000000 rot2= 0.560707 rot3= -0.000065 radDirectBeamDist= 951.518mm Center: x=267.438, y=2975.017 pix Tilt=32.126→˓deg tiltPlanRotation= 90.000 deg
del_33.5_0001p Angle: 33.5Detector Pilatus 100k PixelSize= 1.720e-04, 1.720e-04 mWavelength= 7.749012e-11mSampleDetDist= 8.061475e-01m PONI= 1.998418e-02, 4.623309e-02m rot1=0.→˓000061 rot2= 0.577898 rot3= -0.000000 radDirectBeamDist= 962.435mm Center: x=268.511, y=3172.837 pix Tilt=33.111→˓deg tiltPlanRotation= 90.005 deg
del_35.0_0001p Angle: 35.0Detector Pilatus 100k PixelSize= 1.720e-04, 1.720e-04 mWavelength= 7.749012e-11mSampleDetDist= 8.053432e-01m PONI= 5.551240e-03, 4.624546e-02m rot1=-→˓0.000016 rot2= 0.622009 rot3= 0.000012 radDirectBeamDist= 990.936mm Center: x=268.944, y=3389.181 pix Tilt=35.638→˓deg tiltPlanRotation= 89.999 deg
del_35.5_0001p Angle: 35.5Detector Pilatus 100k PixelSize= 1.720e-04, 1.720e-04 mWavelength= 7.749012e-11mSampleDetDist= 8.061272e-01m PONI= 5.998339e-03, 3.450065e-02m rot1=-→˓0.014779 rot2= 0.630136 rot3= 0.000007 radDirectBeamDist= 997.856mm Center: x=269.857, y=3453.432 pix Tilt=36.113→˓deg tiltPlanRotation= 88.839 deg
Filled refinement object:GoniometerRefinement with 4 geometries labeled: del_31.5_0001p, del_33.5_0001p,→˓del_35.0_0001p, del_35.5_0001p.
#Display all images with associated calibration:
for sg in gonioref.single_geometries.values():
84 Chapter 3. Tutorials
![Page 89: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/89.jpg)
pyFAI Documentation, Release 0.15.0a0
jupyter.display(sg=sg)
<IPython.core.display.Javascript object>
<IPython.core.display.Javascript object>
<IPython.core.display.Javascript object>
<IPython.core.display.Javascript object>
# Initial refinement of the goniometer model with 5 dof
gonioref.refine2()
Cost function before refinement: 4.67628027948e-05fun: 3.474545890145023e-09jac: array([ 1.55798008e-08, 6.20442923e-08, -8.86840831e-09,
9.38196637e-09, 4.54171855e-08, 5.30002449e-06])message: 'Optimization terminated successfully.'
nfev: 145nit: 18
njev: 18status: 0
success: Truex: array([ 0.80587963, 0.01626972, 0.04374852, -0.00299843, -0.00217847,0.01745329])
Cost function after refinement: 3.474545890145023e-09GonioParam(dist=0.80587963251952144, poni1=0.016269720064575065, poni2=0.→˓04374852465218073, rot1=-0.0029984302141578345, rot2_offset=-0.→˓0021784698875247318, rot2_scale=0.017453292519943295)maxdelta on: dist (0) 0.8 --> 0.80587963252
array([ 0.80587963, 0.01626972, 0.04374852, -0.00299843, -0.00217847,0.01745329])
# This function adds new images to the pool of data used for the refinement.# A set of new control points are extractred and a refinement step is performed at→˓each iteration# The last image of the serie is displayed
def optimize_with_new_images(list_images, pts_per_deg=1):sg = Nonefor fname in list_images:
print()basename = os.path.basename(fname)base = os.path.splitext(basename)[0]fimg = fabio.open(fname)if base in gonioref.single_geometries:
continueprint(base)sg = gonioref.new_geometry(base, image=fimg.data, metadata=base,
calibrant=LaB6)print(sg.extract_cp(pts_per_deg=pts_per_deg))
print("*"*50)gonioref.refine2()if sg:
sg.geometry_refinement.set_param(gonioref.get_ai(sg.get_position()).param)jupyter.display(sg=sg)
3.8. Goniometer and translation table calibration 85
![Page 90: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/90.jpg)
pyFAI Documentation, Release 0.15.0a0
# Append all other images bewteen 30 and 40 degrees
images_30_40 = [i for i in all_files if ("del_3" in i and i.endswith("0001p.cbf"))]random.shuffle(images_30_40)optimize_with_new_images(images_30_40, pts_per_deg=3)
del_30.5_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:# c ring 6: 36 points
del_38.5_0001pControlPoints instance containing 2 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 2 groups of points:# d ring 10: 30 points# e ring 11: 30 points
del_37.5_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:# f ring 10: 30 points
del_36.0_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:# g ring 9: 36 points
del_32.5_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:# h ring 7: 36 points
del_37.0_0001pControlPoints instance containing 2 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 2 groups of points:# i ring 9: 36 points# j ring 10: 30 points
del_38.0_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:# k ring 10: 30 points
del_32.0_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:# l ring 7: 36 points
86 Chapter 3. Tutorials
![Page 91: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/91.jpg)
pyFAI Documentation, Release 0.15.0a0
del_34.5_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:# m ring 8: 36 points
del_36.5_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:# n ring 9: 36 points
del_39.5_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:# o ring 11: 30 points
del_30.0_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:# p ring 6: 36 points
del_33.0_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:# q ring 7: 36 points
del_39.0_0001pControlPoints instance containing 2 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 2 groups of points:# r ring 10: 15 points# s ring 11: 30 points
del_31.0_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:# t ring 6: 36 points
del_34.0_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:# u ring 8: 36 points
**********************************************Cost function before refinement: 3.78586503256e-09
fun: 3.785478428600372e-09jac: array([ 2.02798652e-08, -1.40537854e-06, -4.03506535e-07,
3.25207815e-07, -1.13637203e-06, -7.90020799e-05])message: 'Optimization terminated successfully.'
nfev: 10nit: 1
3.8. Goniometer and translation table calibration 87
![Page 92: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/92.jpg)
pyFAI Documentation, Release 0.15.0a0
njev: 1status: 0success: True
x: array([ 0.80587963, 0.01627002, 0.04374861, -0.0029985 , -0.→˓00217823,
0.01745329])Cost function after refinement: 3.785478428600372e-09GonioParam(dist=0.80587962817888781, poni1=0.016270020867037542, poni2=0.
→˓043748611017352793, rot1=-0.0029984998205369322, rot2_offset=-0.→˓0021782266623036049, rot2_scale=0.017453292519943295)maxdelta on: poni1 (1) 0.0162697200646 --> 0.016270020867
<IPython.core.display.Javascript object>
# Append all other images
all_images = [i for i in all_files if i.endswith(".cbf")]random.shuffle(all_images)optimize_with_new_images(all_images)
del_44.5_0001pControlPoints instance containing 2 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 2 groups of points:# v ring 13: 10 points# w ring 14: 10 points
del_54.0_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:# x ring 20: 8 points
del_11.0_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:# y ring 0: 32 points
del_15.5_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:# z ring 1: 24 points
del_59.0_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#aa ring 23: 6 points
del_05.5_0001pControlPoints instance containing 0 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 0 groups of points:
del_42.0_0001pControlPoints instance containing 1 group of point:
88 Chapter 3. Tutorials
![Page 93: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/93.jpg)
pyFAI Documentation, Release 0.15.0a0
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#ab ring 12: 10 points
del_25.5_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#ac ring 5: 14 points
del_14.5_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#ad ring 1: 24 points
del_51.5_0001pControlPoints instance containing 2 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 2 groups of points:#ae ring 18: 7 points#af ring 19: 8 points
del_53.5_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#ag ring 20: 8 points
del_14.0_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#ah ring 1: 10 points
del_17.5_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#ai ring 2: 10 points
del_10.5_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#aj ring 0: 34 points
del_22.5_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#ak ring 3: 17 points
del_25.0_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:
3.8. Goniometer and translation table calibration 89
![Page 94: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/94.jpg)
pyFAI Documentation, Release 0.15.0a0
#al ring 4: 16 points
del_10.0_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#am ring 0: 26 points
del_23.5_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#an ring 4: 16 points
del_62.5_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#ao ring 25: 8 points
del_21.0_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#ap ring 3: 17 points
del_42.5_0001pControlPoints instance containing 0 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 0 groups of points:
del_47.0_0001pControlPoints instance containing 2 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 2 groups of points:#aq ring 15: 10 points#ar ring 16: 9 points
del_41.5_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#as ring 12: 10 points
del_18.5_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#at ring 2: 19 points
del_64.5_0001pControlPoints instance containing 2 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 2 groups of points:#au ring 26: 8 points#av ring 27: 8 points
90 Chapter 3. Tutorials
![Page 95: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/95.jpg)
pyFAI Documentation, Release 0.15.0a0
del_09.0_0001pControlPoints instance containing 0 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 0 groups of points:
del_20.0_0001pControlPoints instance containing 0 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 0 groups of points:
del_58.0_0001pControlPoints instance containing 2 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 2 groups of points:#aw ring 22: 7 points#ax ring 23: 8 points
del_54.5_0001pControlPoints instance containing 2 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 2 groups of points:#ay ring 20: 8 points#az ring 21: 3 points
del_47.5_0001pControlPoints instance containing 2 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 2 groups of points:#ba ring 15: 10 points#bb ring 16: 9 points
del_29.0_0001pControlPoints instance containing 0 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 0 groups of points:
del_55.5_0001pControlPoints instance containing 2 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 2 groups of points:#bc ring 20: 8 points#bd ring 21: 8 points
del_57.5_0001pControlPoints instance containing 2 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 2 groups of points:#be ring 22: 7 points#bf ring 23: 7 points
del_13.5_0001pControlPoints instance containing 0 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 0 groups of points:
3.8. Goniometer and translation table calibration 91
![Page 96: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/96.jpg)
pyFAI Documentation, Release 0.15.0a0
del_29.5_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#bg ring 6: 7 points
del_12.5_0001pControlPoints instance containing 0 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 0 groups of points:
del_51.0_0001pControlPoints instance containing 2 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 2 groups of points:#bh ring 18: 8 points#bi ring 19: 8 points
del_46.5_0001pControlPoints instance containing 2 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 2 groups of points:#bj ring 14: 7 points#bk ring 15: 10 points
del_06.5_0001pControlPoints instance containing 0 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 0 groups of points:
del_59.5_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#bl ring 24: 8 points
del_26.0_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#bm ring 5: 14 points
del_43.0_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#bn ring 13: 10 points
del_16.0_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#bo ring 1: 24 points
92 Chapter 3. Tutorials
![Page 97: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/97.jpg)
pyFAI Documentation, Release 0.15.0a0
del_22.0_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#bp ring 3: 17 points
del_20.5_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#bq ring 3: 17 points
del_57.0_0001pControlPoints instance containing 2 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 2 groups of points:#br ring 22: 8 points#bs ring 23: 8 points
del_56.5_0001pControlPoints instance containing 2 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 2 groups of points:#bt ring 21: 8 points#bu ring 22: 8 points
del_07.0_0001pControlPoints instance containing 0 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 0 groups of points:
del_52.0_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#bv ring 19: 8 points
del_21.5_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#bw ring 3: 17 points
del_40.5_0001pControlPoints instance containing 2 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 2 groups of points:#bx ring 11: 10 points#by ring 12: 10 points
del_43.5_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#bz ring 13: 10 points
del_55.0_0001pControlPoints instance containing 2 group of point:
3.8. Goniometer and translation table calibration 93
![Page 98: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/98.jpg)
pyFAI Documentation, Release 0.15.0a0
LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 2 groups of points:#ca ring 20: 8 points#cb ring 21: 8 points
del_06.0_0001pControlPoints instance containing 0 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 0 groups of points:
del_13.0_0001pControlPoints instance containing 0 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 0 groups of points:
del_27.0_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#cc ring 5: 14 points
del_61.5_0001pControlPoints instance containing 2 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 2 groups of points:#cd ring 24: 8 points#ce ring 25: 8 points
del_28.0_0001pControlPoints instance containing 0 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 0 groups of points:
del_49.5_0001pControlPoints instance containing 2 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 2 groups of points:#cf ring 17: 9 points#cg ring 18: 3 points
del_26.5_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#ch ring 5: 14 points
del_63.5_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#ci ring 26: 8 points
del_24.5_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11
94 Chapter 3. Tutorials
![Page 99: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/99.jpg)
pyFAI Documentation, Release 0.15.0a0
Containing 1 groups of points:#cj ring 4: 16 points
del_17.0_0001pControlPoints instance containing 0 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 0 groups of points:
del_07.5_0001pControlPoints instance containing 0 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 0 groups of points:
del_65.0_0001pControlPoints instance containing 2 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 2 groups of points:#ck ring 27: 7 points#cl ring 28: 8 points
del_48.5_0001pControlPoints instance containing 2 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 2 groups of points:#cm ring 16: 9 points#cn ring 17: 9 points
del_18.0_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#co ring 2: 19 points
del_19.0_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#cp ring 2: 19 points
del_45.5_0001pControlPoints instance containing 2 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 2 groups of points:#cq ring 14: 10 points#cr ring 15: 2 points
del_61.0_0001pControlPoints instance containing 2 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 2 groups of points:#cs ring 24: 8 points#ct ring 25: 8 points
3.8. Goniometer and translation table calibration 95
![Page 100: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/100.jpg)
pyFAI Documentation, Release 0.15.0a0
del_53.0_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#cu ring 19: 8 points
del_60.5_0001pControlPoints instance containing 2 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 2 groups of points:#cv ring 24: 8 points#cw ring 25: 8 points
del_24.0_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#cx ring 4: 16 points
del_05.0_0001pControlPoints instance containing 0 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 0 groups of points:
del_40.0_0001pControlPoints instance containing 2 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 2 groups of points:#cy ring 11: 9 points#cz ring 12: 10 points
del_48.0_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#da ring 16: 9 points
del_28.5_0001pControlPoints instance containing 0 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 0 groups of points:
del_08.0_0001pControlPoints instance containing 0 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 0 groups of points:
del_09.5_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#db ring 0: 14 points
del_08.5_0001pControlPoints instance containing 0 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 0 groups of points:
96 Chapter 3. Tutorials
![Page 101: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/101.jpg)
pyFAI Documentation, Release 0.15.0a0
del_41.0_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#dc ring 12: 10 points
del_64.0_0001pControlPoints instance containing 2 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 2 groups of points:#dd ring 26: 8 points#de ring 27: 8 points
del_45.0_0001pControlPoints instance containing 2 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 2 groups of points:#df ring 13: 10 points#dg ring 14: 10 points
del_15.0_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#dh ring 1: 24 points
del_63.0_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#di ring 26: 8 points
del_12.0_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#dj ring 0: 11 points
del_56.0_0001pControlPoints instance containing 2 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 2 groups of points:#dk ring 21: 8 points#dl ring 22: 8 points
del_62.0_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#dm ring 25: 8 points
del_52.5_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#dn ring 19: 8 points
3.8. Goniometer and translation table calibration 97
![Page 102: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/102.jpg)
pyFAI Documentation, Release 0.15.0a0
del_27.5_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#do ring 5: 14 points
del_44.0_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#dp ring 13: 10 points
del_50.5_0001pControlPoints instance containing 2 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 2 groups of points:#dq ring 17: 9 points#dr ring 18: 8 points
del_19.5_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#ds ring 2: 19 points
del_50.0_0001pControlPoints instance containing 2 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 2 groups of points:#dt ring 17: 9 points#du ring 18: 8 points
del_23.0_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#dv ring 4: 11 points
del_60.0_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#dw ring 24: 8 points
del_46.0_0001pControlPoints instance containing 2 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 2 groups of points:#dx ring 14: 10 points#dy ring 15: 10 points
del_11.5_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#dz ring 0: 30 points
98 Chapter 3. Tutorials
![Page 103: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/103.jpg)
pyFAI Documentation, Release 0.15.0a0
del_16.5_0001pControlPoints instance containing 0 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 0 groups of points:
del_58.5_0001pControlPoints instance containing 1 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 1 groups of points:#ea ring 23: 8 points
del_49.0_0001pControlPoints instance containing 2 group of point:LaB6 Calibrant with 97 reflections at wavelength 7.7490120575e-11Containing 2 groups of points:#eb ring 16: 9 points#ec ring 17: 9 points
**********************************************Cost function before refinement: 1.5418692807e-08
fun: 1.2653965346381429e-08jac: array([ -7.40160115e-08, 8.08276352e-07, -1.43417888e-08,
5.60775004e-09, 6.52925588e-07, -1.01581876e-03])message: 'Optimization terminated successfully.'
nfev: 49nit: 6
njev: 6status: 0success: True
x: array([ 0.80588628, 0.01627363, 0.043281 , -0.00262053, -0.→˓002175 ,
0.01745329])Cost function after refinement: 1.2653965346381429e-08GonioParam(dist=0.80588628202624024, poni1=0.016273634721444413, poni2=0.
→˓043280998683283237, rot1=-0.0026205297731339019, rot2_offset=-0.→˓0021749982834775843, rot2_scale=0.017453292519943295)maxdelta on: poni2 (2) 0.0437486110174 --> 0.0432809986833
<IPython.core.display.Javascript object>
# Check the calibration of the first and the last image with rings
print("First & last rings")
print("Total number of images:", len(gonioref.single_geometries) )
fig = plt.figure()for idx,lbl in enumerate(["del_10.0_0001p", "del_65.0_0001p"]):
sg = gonioref.single_geometries[lbl]if sg.control_points.get_labels():
sg.geometry_refinement.set_param(gonioref.get_ai(sg.get_position()).param)jupyter.display(sg=sg, ax=fig.add_subplot(2, 1, idx+1))
First & last ringsTotal number of images: 121
<IPython.core.display.Javascript object>
3.8. Goniometer and translation table calibration 99
![Page 104: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/104.jpg)
pyFAI Documentation, Release 0.15.0a0
# Final pass of refinement with all constrains removed, very fine refinement
gonioref.bounds = Nonegonioref.refine2("slsqp", eps=1e-13, maxiter=10000, ftol=1e-12)
Cost function before refinement: 1.26539653464e-08fun: 1.1079685608729184e-08jac: array([ 5.21785530e-08, 1.26889506e-08, 5.26831332e-07,
-4.24227849e-07, 1.14978105e-08, 1.42936810e-08])message: 'Optimization terminated successfully.'
nfev: 36nit: 4
njev: 4status: 0
success: Truex: array([ 0.8058864 , 0.01622186, 0.04328034, -0.00261997, -0.00221674,0.01745626])
Cost function after refinement: 1.1079685608729184e-08GonioParam(dist=0.80588640493195618, poni1=0.016221864667863021, poni2=0.→˓043280336616327734, rot1=-0.0026199663308397385, rot2_offset=-0.→˓0022167400134821824, rot2_scale=0.017456261552178831)maxdelta on: poni1 (1) 0.0162736347214 --> 0.0162218646679
array([ 0.8058864 , 0.01622186, 0.04328034, -0.00261997, -0.00221674,0.01745626])
#Create a MultiGeometry integrator from the refined geometry:
angles = []images = []for sg in gonioref.single_geometries.values():
angles.append(sg.get_position())images.append(sg.image)
multigeo = gonioref.get_mg(angles)multigeo.radial_range=(3, 68)print(multigeo)
MultiGeometry integrator with 121 geometries on (3, 68) radial range (2th_deg) and→˓(-180, 180) azimuthal range (deg)
# Integrate the whole set of images in a single run:
res = multigeo.integrate1d(images, 10000)jupyter.plot1d(res)
<IPython.core.display.Javascript object>
<matplotlib.axes._subplots.AxesSubplot at 0x7ffad1ff95f8>
# Save the goniometer configuration with 1 angle
gonioref.save("ROBL_v1.json")
#Can the refinement be improved by freeing another degree of freedom ? what about→˓rot1 ?
goniotrans2 = GeometryTransformation(param_names = ["dist", "poni1", "poni2","rot1", "rot1_scale",
100 Chapter 3. Tutorials
![Page 105: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/105.jpg)
pyFAI Documentation, Release 0.15.0a0
"rot2_offset", "rot2_scale"],dist_expr="dist",poni1_expr="poni1",poni2_expr="poni2",rot1_expr="rot1_scale * pos + rot1",rot2_expr="rot2_scale * pos + rot2_offset",rot3_expr="0.0")
param2 = (gonioref.nt_param(*gonioref.param))._asdict()param2["rot1_scale"] = 0
gonioref2 = GoniometerRefinement(param2,pos_function = get_angle,trans_function=goniotrans2,detector=pilatus,wavelength=wavelength)
gonioref2.single_geometries = gonioref.single_geometries.copy()
print(gonioref2.chi2(), gonioref.chi2())gonioref2.refine2()gonioref2.save("ROBL_v2.json")
1.10796856087e-08 1.10796856087e-08Cost function before refinement: 1.10796856087e-08
fun: 4.754350840871057e-09jac: array([ 5.35082313e-08, -1.10894246e-07, -5.29857408e-09,
4.75679152e-09, 1.68307757e-08, -9.27227720e-08,-3.88850517e-06])
message: 'Optimization terminated successfully.'nfev: 121nit: 13
njev: 13status: 0
success: Truex: array([ 8.05873589e-01, 1.62083546e-02, 4.17665409e-02,-1.39612789e-03, -1.28555852e-04, -2.22689562e-03,1.74566332e-02])
Cost function after refinement: 4.754350840871057e-09GonioParam(dist=0.80587358868352343, poni1=0.016208354569446009, poni2=0.→˓041766540922984097, rot1=-0.0013961278865829037, rot1_scale=-0.→˓00012855585206377195, rot2_offset=-0.0022268956160008172, rot2_scale=0.→˓017456633219776127)maxdelta on: poni2 (2) 0.0432803366163 --> 0.041766540923
# Check the calibration of the first and the last image with rings
print("First & last rings")
fig = plt.figure()for idx,lbl in enumerate(["del_10.0_0001p", "del_65.0_0001p"]):
sg = gonioref.single_geometries[lbl]if sg.control_points.get_labels():
sg.geometry_refinement.set_param(gonioref2.get_ai(sg.get_position()).param)jupyter.display(sg=sg, ax=fig.add_subplot(2, 1, idx+1))
First & last rings
<IPython.core.display.Javascript object>
3.8. Goniometer and translation table calibration 101
![Page 106: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/106.jpg)
pyFAI Documentation, Release 0.15.0a0
#Create a MultiGeometry integrator from the refined geometry and display the→˓integrated image:
multigeo2 = gonioref2.get_mg(angles)multigeo2.radial_range=(3, 68)print(multigeo2)
res2 = multigeo2.integrate1d(images, 10000)
#Display the 2 curves with a zoomfig = figure(figsize=(10,5))ax = fig.add_subplot(1,2,1)ax.plot(*res2, label="rot1 & rot2 rotation")ax.plot(*res, label="rot2 only rotation")ax.set_xlabel(res.unit.label)ax.set_ylabel("Intensity")ax.set_title("Azimuthal integration of 121 images merged")ax.legend()ay = fig.add_subplot(1,2,2)ay.plot(*res2, label="rot1 & rot2 rotation")ay.plot(*res, label="rot2 only rotation")ay.set_xlabel(res.unit.label)ay.set_ylabel("Intensity")ay.set_xlim(10.5,11)ay.set_title("Zoom on first peak")ay.legend()
MultiGeometry integrator with 121 geometries on (3, 68) radial range (2th_deg) and→˓(-180, 180) azimuthal range (deg)
<IPython.core.display.Javascript object>
<matplotlib.legend.Legend at 0x7ffad1b43cf8>
print("Total execution time: %.3fs"%(time.time() - start_time))
Total execution time: 33.339s
With the first model, the refinement was not perfect on the very low angles and indicates a miss-fit. Relaxingthe constrains on rot1 allowed to spot a non (perfect) orthogonality between the goniometer axis and the incidentbeam. Releasing the distances is also possible, for example to cope with the sample not perfectly mounted on thecenter of the goniometer.
Conclusion
This notebook exposes the how to calibrate the goniometer for a small detector moving on a 2theta arm. Oncecalibrated, the geometry can be saved and restored and stays valid as long as the detector or the goniometer is notunmounted from the beam-line. This configuration can subsequently be used to integrate the data acquired withany sample, in minutes instead of hours. The resolution limit is now the pixel size. Fortunately, pixel detectorwith small pixel like the MaxiPix or the Lambda detector exists and offer higher resolution.
ImXPAD S540 detector at D2AM
This tutorial corresponds to the calibration the goniometer an ImXPAD detector composed of 8 stripes of 7 mod-ules, many of which are defective, on a goniometer.
This detector is mounted on the goniometer 2theta arm at the D2AM beam-line, French CRG at the ESRF syn-chrotron.
102 Chapter 3. Tutorials
![Page 107: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/107.jpg)
pyFAI Documentation, Release 0.15.0a0
The raw data files are available at: http://www.silx.org/pub/pyFAI/gonio/D2AM-15/
%pylab nbagg
Populating the interactive namespace from numpy and matplotlib
import os, timestart_time = time.time()import fabio, pyFAIfrom pyFAI.goniometer import GeometryTransformation, GoniometerRefinement,→˓Goniometerfrom pyFAI.gui import jupyter
#Download all data
from silx.resources import ExternalResources
#Specific for ESRFos.environ["http_proxy"] = "http://proxy.esrf.fr:3128"
downloader = ExternalResources("pyFAI", "http://www.silx.org/pub/pyFAI/testimages",→˓ "PYFAI_DATA")all_files = downloader.getdir("LaB6_gonio_D2AM.tar.bz2")
print("List of files downloaded:")for i in all_files:
print(" "+os.path.basename(i))
detector_file = [i for i in all_files if i.endswith("D5Geom.h5")][0]images = [i for i in all_files if i.endswith(".edf")]npt_files = [i for i in all_files if i.endswith(".npt")]
List of files downloaded:LaB6_gonio_D2AM16Dec08D5_1763-rsz.edf16Dec08D5_1730-rsz.npt16Dec08D5_1725-rsz.npt16Dec08D5_1749-rsz.npt16Dec08D5_1735-rsz.npt16Dec08D5_1763-rsz.npt16Dec08D5_1729-rsz.npt16Dec08D5_1728-rsz.npt16Dec08D5_1791-rsz.nptD5Geom.h516Dec08D5_1725-rsz.edf16Dec08D5_1742-rsz.edf16Dec08D5_1726-rsz.npt16Dec08D5_1784-rsz.npt16Dec08D5_1777-rsz.npt16Dec08D5_1791-rsz.edf16Dec08D5_1729-rsz.edf16Dec08D5_1770-rsz.npt16Dec08D5_1742-rsz.npt16Dec08D5_1770-rsz.edf16Dec08D5_1726-rsz.edf16Dec08D5_1784-rsz.edf16Dec08D5_1749-rsz.edf16Dec08D5_1730-rsz.edf16Dec08D5_1728-rsz.edf16Dec08D5_1727-rsz.npt16Dec08D5_1756-rsz.npt16Dec08D5_1756-rsz.edf
3.8. Goniometer and translation table calibration 103
![Page 108: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/108.jpg)
pyFAI Documentation, Release 0.15.0a0
16Dec08D5_1735-rsz.edf16Dec08D5_1727-rsz.edf16Dec08D5_1777-rsz.edf
#Definition of the detector and deplay of an image and its mask:
d5 = pyFAI.detector_factory(detector_file)print("Detector shape: ",d5.shape)
fimg = fabio.open(images[-1])
for k,v in fimg.header.items():print(k, ": ", v)
f, ax = subplots(1, 2)jupyter.display(d5.mask, label="mask", ax=ax[0])jupyter.display(fimg.data, label=os.path.basename(fimg.filename), ax=ax[1])
Detector shape: (960, 578)EDF_DataBlockID : 0.Image.PsdEDF_BinarySize : 4439040EDF_HeaderSize : 1536ByteOrder : LowByteFirstDataType : DoubleValueDim_1 : 578Dim_2 : 960Image : 0HeaderID : EH:000000:000000:000000Size : 4439040VersionNumber : 1Epoch : 1481330682.5452539921det_sample_dist : 0y_beam : 0x_beam : 0Lambda : 0.495938offset : 0count_time : 120point_no : 52scan_no : 906preset : 0col_end : 559col_beg : 0row_end : 959row_beg : 0counter_pos : 120 2733 166 15.3905 0 91.0146 15.3905 0 25 25 1777 7.45541e+09 0 0→˓0 174.822 0 0 15.3905counter_mne : sec vct1 vct2 vct3 vct4 Imach pseudoC pfoil Emono Ecod img roi1→˓roi2 roi3 roi4 pico1 pico2 pico3 pico4motor_pos : 52 0.078446 89.991 -89.9919 -0.0031 0.0021 57.1196 134.747 -32.9501 0.→˓16656 -5 0.47558 -1.5 0 0 0 4.53604 0.1416 1.04 1.04022 1.04022 -4.4 -1.10211 -0.→˓543725 -9.962 -14.038 -16.865 -7.195 24 -2.038 24.06 4.835 1motor_mne : del eta chi phi nu mu keta kap kphi tsx tsy tsz rox roy tox toy mono→˓inc1 courb courbb courbf omega khimono gamma su6 sd6 sf6 sb6 vg6 vo6 hg6 ho6 riensuffix : .edfprefix : 16Dec08D5_dir : /users/opd02/rawrun : 1777title : CCD Image
<IPython.core.display.Javascript object>
104 Chapter 3. Tutorials
![Page 109: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/109.jpg)
pyFAI Documentation, Release 0.15.0a0
<matplotlib.axes._subplots.AxesSubplot at 0x7f9d76737080>
# Define wavelength and create our "large" LaB6 calibrant
wavelength = 0.495938 * 1e-10from pyFAI.calibrant import get_calibrantLaB6 = get_calibrant("LaB6")LaB6.wavelength = wavelengthprint("2theta max: ", numpy.degrees(LaB6.get_2th()[-1]))print("Number of reflections: ", len(LaB6.get_2th()))
2theta max: 179.173497672Number of reflections: 236
#Use a few manually calibrated images:
npt_files.sort()print("Number of hand-calibrated images :",len(npt_files))
Number of hand-calibrated images : 15
# Definition of the goniometer translation function:# The detector rotates vertically, around the horizontal axis, i.e. rot2.# Rotation both around axis 1 and axis 2 are allowed
goniotrans = GeometryTransformation(param_names = ["dist", "poni1", "poni2","rot1", "rot2", "rot3", "scale1
→˓", "scale2" ],dist_expr="dist",poni1_expr="poni1",poni2_expr="poni2",rot1_expr="scale1 * pos +rot1",rot2_expr="scale2 * pos + rot2",rot3_expr="rot3")
#Definition of the function reading the goniometer angle from the filename of the→˓image.
def get_angle(metadata):"""Takes the angle from the first motor position and returns the angle of the
→˓goniometer arm"""return float(metadata["motor_pos"].split()[0])
print('filename', os.path.basename(fimg.filename), "angle:",get_angle(fimg.header))
filename 16Dec08D5_1777-rsz.edf angle: 52.0
# Definition of the geometry refinement: the parameter order is the same as the→˓param_names
rot3 = numpy.pi/2scale1 = -numpy.pi/180scale2 = 0param = {"dist":0.5,
"poni1":0.05,"poni2":0.05,"rot1":0,"rot2":0,"rot3": rot3,
3.8. Goniometer and translation table calibration 105
![Page 110: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/110.jpg)
pyFAI Documentation, Release 0.15.0a0
"scale1": scale1,"scale2": scale2,}
#Defines the bounds for some variablesbounds = {"dist": (0.2, 0.8),
"poni1": (0, 0.1),"poni2": (0, 0.1),"rot1": (-0.1, 0.1),"rot2": (-0.1, 0.1),"rot3": (rot3, rot3), #strict bounds on rot3#"scale1": (scale1, scale1),#"scale2": (scale2, scale2),
}gonioref = GoniometerRefinement(param, #initial guess
bounds=bounds,pos_function=get_angle,trans_function=goniotrans,detector=d5, wavelength=wavelength)
print("Empty refinement object:", gonioref)
#Let's populate the goniometer refinement object with all control point files:
for fn in npt_files[:]:base = os.path.splitext(fn)[0]fimg = fabio.open(base + ".edf")basename = os.path.basename(base)sg =gonioref.new_geometry(basename, image=fimg.data, metadata=fimg.header,
→˓control_points=fn, calibrant=LaB6)print(basename, "Angle:", sg.get_position())
print("Filled refinement object:")print(gonioref)
Empty refinement object: GoniometerRefinement with 0 geometries labeled: .16Dec08D5_1725-rsz Angle: -0.00316Dec08D5_1726-rsz Angle: 0.999816Dec08D5_1727-rsz Angle: 2.016Dec08D5_1728-rsz Angle: 2.999816Dec08D5_1729-rsz Angle: 4.000216Dec08D5_1730-rsz Angle: 4.999816Dec08D5_1735-rsz Angle: 10.000116Dec08D5_1742-rsz Angle: 16.999616Dec08D5_1749-rsz Angle: 24.000116Dec08D5_1756-rsz Angle: 30.999716Dec08D5_1763-rsz Angle: 37.999916Dec08D5_1770-rsz Angle: 44.999716Dec08D5_1777-rsz Angle: 52.016Dec08D5_1784-rsz Angle: 58.999516Dec08D5_1791-rsz Angle: 65.9999Filled refinement object:GoniometerRefinement with 15 geometries labeled: 16Dec08D5_1725-rsz, 16Dec08D5_→˓1726-rsz, 16Dec08D5_1727-rsz, 16Dec08D5_1728-rsz, 16Dec08D5_1729-rsz, 16Dec08D5_→˓1730-rsz, 16Dec08D5_1735-rsz, 16Dec08D5_1742-rsz, 16Dec08D5_1749-rsz, 16Dec08D5_→˓1756-rsz, 16Dec08D5_1763-rsz, 16Dec08D5_1770-rsz, 16Dec08D5_1777-rsz, 16Dec08D5_→˓1784-rsz, 16Dec08D5_1791-rsz.
# Initial refinement of the goniometer model with 5 dof
gonioref.refine2()
106 Chapter 3. Tutorials
![Page 111: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/111.jpg)
pyFAI Documentation, Release 0.15.0a0
Cost function before refinement: 0.000307661216084fun: 1.9855225499763415e-08jac: array([ 2.40901503e-08, 3.04893444e-07, 4.13717251e-07,
-1.75578498e-07, -9.57395104e-07, -4.24105195e-14,-5.24620326e-06, -7.15065733e-07])
message: 'Optimization terminated successfully.'nfev: 178nit: 17
njev: 17status: 0
success: Truex: array([ 5.20464974e-01, 6.34779274e-02, 4.46077058e-02,3.03313915e-03, 7.46909754e-03, 1.57079633e+00,-1.74719084e-02, -3.84262989e-04])
Cost function after refinement: 1.9855225499763415e-08GonioParam(dist=0.52046497446866713, poni1=0.063477927428416264, poni2=0.→˓04460770577505211, rot1=0.0030331391536378505, rot2=0.0074690975437223016,→˓rot3=1.5707963267948966, scale1=-0.017471908444279767, scale2=-0.→˓00038426298857720866)maxdelta on: dist (0) 0.5 --> 0.520464974469
array([ 5.20464974e-01, 6.34779274e-02, 4.46077058e-02,3.03313915e-03, 7.46909754e-03, 1.57079633e+00,-1.74719084e-02, -3.84262989e-04])
width=3height=int(ceil(len(gonioref.single_geometries) / width))fig,ax = subplots(height, width,figsize=(10, 25))for idx, sg in enumerate(gonioref.single_geometries.values()):
sg.geometry_refinement.set_param(gonioref.get_ai(sg.get_position()).param)jupyter.display(sg=sg, ax=ax[idx//width, idx%width])
<IPython.core.display.Javascript object>
/scisoft/users/jupyter/jupy34/lib/python3.4/site-packages/matplotlib/axes/_axes.→˓py:545: UserWarning: No labelled objects found. Use label='...' kwarg on→˓individual plots.warnings.warn("No labelled objects found. "
# Final pass of refinement with all constrains removed, very fine refinement
gonioref.bounds = Nonegonioref.refine2("slsqp", eps=1e-13, maxiter=10000, ftol=1e-12)
Cost function before refinement: 1.98552254998e-08fun: 1.9855093592191876e-08jac: array([ 1.03563013e-08, 0.00000000e+00, 0.00000000e+00,
4.48001020e-08, -8.71252796e-07, 2.31610572e-09,-3.46915909e-05, -5.50968462e-07])
message: 'Optimization terminated successfully.'nfev: 15nit: 1
njev: 1status: 0
success: Truex: array([ 5.20464974e-01, 6.34779274e-02, 4.46077058e-02,3.03313914e-03, 7.46909773e-03, 1.57079633e+00,-1.74719008e-02, -3.84262868e-04])
Cost function after refinement: 1.9855093592191876e-08GonioParam(dist=0.52046497446639939, poni1=0.063477927428416264, poni2=0.→˓04460770577505211, rot1=0.0030331391438279576, rot2=0.0074690977345008092,→˓rot3=1.5707963267943894, scale1=-0.01747190084785084, scale2=-0.→˓00038426286793146559)
3.8. Goniometer and translation table calibration 107
![Page 112: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/112.jpg)
pyFAI Documentation, Release 0.15.0a0
maxdelta on: scale1 (6) -0.0174719084443 --> -0.0174719008479
array([ 5.20464974e-01, 6.34779274e-02, 4.46077058e-02,3.03313914e-03, 7.46909773e-03, 1.57079633e+00,-1.74719008e-02, -3.84262868e-04])
#Create a MultiGeometry integrator from the refined geometry:
angles = []images = []for sg in gonioref.single_geometries.values():
angles.append(sg.get_position())images.append(sg.image)
multigeo = gonioref.get_mg(angles)multigeo.radial_range=(0, 80)print(multigeo)
MultiGeometry integrator with 15 geometries on (0, 80) radial range (2th_deg) and→˓(-180, 180) azimuthal range (deg)
# Integrate the whole set of images in a single run:
res = multigeo.integrate1d(images, 10000)jupyter.plot1d(res)
#Note the large number of peaks due to hot pixels ....
<IPython.core.display.Javascript object>
<matplotlib.axes._subplots.AxesSubplot at 0x7f9d10ade7f0>
#Add hot pixels to the mask: pixel which are 15x more intense than the median in→˓their ring.
thres = 15
old_mask = d5.mask.astype("bool", copy=True)new_mask = d5.mask.astype("bool", copy=True)
for ai,img in zip(multigeo.ais,images):b,a = ai.separate(img, 1000, restore_mask=0)b[old_mask] = 0b[b<0] = 0print(sum(b>thres*a))new_mask = numpy.logical_or(new_mask, (b>thres*a))
print(" Size of old mask", sum(old_mask)," Size of new mask",sum(new_mask)," Number of pixel discarded", sum(new_mask)-sum(old_mask))
44444444
108 Chapter 3. Tutorials
![Page 113: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/113.jpg)
pyFAI Documentation, Release 0.15.0a0
4443333Size of old mask 198678 Size of new mask 198683 Number of pixel discarded 5
# Update the maskfor ai in multigeo.ais:
ai.detector.mask = new_mask
# Integrate the whole set of images in a single run:res2 = multigeo.integrate1d(images, 10000)ax = jupyter.plot1d(res, label="Before hot-pixel removal")ax.plot(*res2, label="After hot-pixel removal")ax.legend()
<IPython.core.display.Javascript object>
<matplotlib.legend.Legend at 0x7f9d10a215c0>
# Integrate the whole set of images in 2D:
res2d = multigeo.integrate2d(images, 1000, 360)jupyter.plot2d(res2d)
<IPython.core.display.Javascript object>
<matplotlib.axes._subplots.AxesSubplot at 0x7f9d10a37128>
print("Total execution time", time.time()-start_time)
Total execution time 60.505094051361084
Inpainting missing data
Missing data in an image can be an issue, especially when one wants to perform Fourier analysis. This tutorialexplains how to fill-up missing pixels with values which looks “realistic” and introduce as little perturbation aspossible for subsequent analysis. The user should keep the mask nearby and only consider the values of actualpixels and never the one inpainted.
This tutorial will use fully synthetic data to allow comparison between actual (syntetic) data with inpainted values.
The first part of the tutorial is about the generation of a challenging 2D diffraction image with realistic noise andto describe the metric used, then comes the actual tutorial on how to use the inpainting. Finally a benchmark isused based on the metric determined.
Creation of the image
A realistic challenging image should contain:
• Bragg peak rings. We chose LaB6 as guinea-pig, with very sharp peaks, at the limit of the resolution of thedetector
3.9. Inpainting missing data 109
![Page 114: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/114.jpg)
pyFAI Documentation, Release 0.15.0a0
• Some amorphous content
• strong polarization effect
• Poissonian noise
One image will be generated but then multiple ones with different noise to discriminate the effect of the noisefrom other effects.
%pylab nbagg
Populating the interactive namespace from numpy and matplotlib
import pyFAIfrom pyFAI.gui import jupyterimport pyFAI.test.utilstestfrom pyFAI.calibrant import get_calibrantimport timestart_time = time.time()
WARNING:test_integrate_widget:pyFAI.integrate_widget tests disabled (DISPLAY env.→˓variable not set)
detector = pyFAI.detector_factory("Pilatus2MCdTe")mask = detector.mask.copy()nomask = numpy.zeros_like(mask)detector.mask=nomaskai = pyFAI.AzimuthalIntegrator(detector=detector)ai.setFit2D(200, 200, 200)ai.wavelength = 3e-11print(ai)
Detector Pilatus CdTe 2M PixelSize= 1.720e-04, 1.720e-04 mWavelength= 3.000000e-11mSampleDetDist= 2.000000e-01m PONI= 3.440000e-02, 3.440000e-02m rot1=0.→˓000000 rot2= 0.000000 rot3= 0.000000 radDirectBeamDist= 200.000mm Center: x=200.000, y=200.000 pix Tilt=0.000 deg→˓ tiltPlanRotation= 0.000 deg
LaB6 = get_calibrant("LaB6")LaB6.wavelength = ai.wavelengthprint(LaB6)r = ai.array_from_unit(unit="q_nm^-1")decay_b = numpy.exp(-(r-50)**2/2000)bragg = LaB6.fake_calibration_image(ai, Imax=1e4, W=1e-6) * ai.→˓polarization(factor=1.0) * decay_bdecay_a = numpy.exp(-r/100)amorphous = 1000*ai.polarization(factor=1.0)*ai.solidAngleArray() * decay_aimg_nomask = bragg + amorphous#Not the same noise function for all images two imagesimg_nomask = numpy.random.poisson(img_nomask)img_nomask2 = numpy.random.poisson(img_nomask)img = numpy.random.poisson(img_nomask)img[numpy.where(mask)] = -1fig,ax = subplots(1,2, figsize=(10,5))jupyter.display(img=img, label="With mask", ax=ax[0])jupyter.display(img=img_nomask, label="Without mask", ax=ax[1])
LaB6 Calibrant at wavelength 3e-11
110 Chapter 3. Tutorials
![Page 115: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/115.jpg)
pyFAI Documentation, Release 0.15.0a0
<IPython.core.display.Javascript object>
<matplotlib.axes._subplots.AxesSubplot at 0x7f4cb1a061d0>
Note the aliassing effect on the displayed images.
We will measure now the effect after 1D intergeration. We do not correct for polarization on purpose to highlightthe defect one wishes to whipe out. We use a R-factor to describe the quality of the 1D-integrated signal.
wo = ai.integrate1d(img_nomask, 2000, unit="q_nm^-1", method="splitpixel", radial_→˓range=(0,210))wo2 = ai.integrate1d(img_nomask2, 2000, unit="q_nm^-1", method="splitpixel",→˓radial_range=(0,210))wm = ai.integrate1d(img, 2000, unit="q_nm^-1", method="splitpixel", mask=mask,→˓radial_range=(0,210))ax = jupyter.plot1d(wm , label="with_mask")ax.plot(*wo, label="without_mask")ax.plot(*wo2, label="without_mask2")ax.plot(wo.radial, wo.intensity-wm.intensity, label="delta")ax.plot(wo.radial, wo.intensity-wo2.intensity, label="relative-error")ax.legend()print("Between masked and non masked image R= %s"%pyFAI.test.utilstest.Rwp(wm,wo))print("Between two different non-masked images R'= %s"%pyFAI.test.utilstest.→˓Rwp(wo2,wo))
<IPython.core.display.Javascript object>
Between masked and non masked image R= 5.67315744311Between two different non-masked images R'= 0.175106399221
# Effect of the noise on the delta imagefig, ax = subplots()jupyter.display(img=img_nomask-img_nomask2, label="Delta due to noise", ax=ax)ax.figure.colorbar(ax.images[0])
<IPython.core.display.Javascript object>
<matplotlib.colorbar.Colorbar at 0x7f4cb187ad30>
Inpainting
This part describes how to paint the missing pixels for having a “natural-looking image”. The delta image containsthe difference with the original image
#Inpainting:inpainted = ai.inpainting(img, mask=mask, poissonian=True)fig, ax = subplots(1, 2, figsize=(12,5))jupyter.display(img=inpainted, label="Inpainted", ax=ax[0])jupyter.display(img=img_nomask-inpainted, label="Delta", ax=ax[1])ax[1].figure.colorbar(ax[1].images[0])
<IPython.core.display.Javascript object>
<matplotlib.colorbar.Colorbar at 0x7f4ca5031668>
# Comparison of the inpained image with the original one:wm = ai.integrate1d(inpainted, 2000, unit="q_nm^-1", method="splitpixel", radial_→˓range=(0,210))
3.9. Inpainting missing data 111
![Page 116: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/116.jpg)
pyFAI Documentation, Release 0.15.0a0
wo = ai.integrate1d(img_nomask, 2000, unit="q_nm^-1", method="splitpixel", radial_→˓range=(0,210))ax = jupyter.plot1d(wm , label="inpainted")ax.plot(*wo, label="without_mask")ax.plot(wo.radial, wo.intensity-wm.intensity, label="delta")ax.legend()print("R= %s"%pyFAI.test.utilstest.Rwp(wm,wo))
<IPython.core.display.Javascript object>
R= 1.29109163117
One can see by zooming in that the main effect on inpainting is a broadening of the signal in the inpainted region.This could (partially) be adressed by increasing the number of radial bins used in the inpainting.
Benchmarking and optimization of the parameters
The parameter set depends on the detector, the experiment geometry and the type of signal on the detector. Finerdetail require finer slicing.
#Basic benchmarking of execution time for default options:% timeit inpainted = ai.inpainting(img, mask=mask)
1 loop, best of 3: 1.04 s per loop
wo = ai.integrate1d(img_nomask, 2000, unit="q_nm^-1", method="splitpixel", radial_→˓range=(0,210))for j in ("csr", "csr_nosplit"):
for k in (512,1024,2048, 4096):ai.reset()for i in range(10):
inpainted = ai.inpainting(img, mask=mask, poissonian=True, method=j,→˓npt_rad=k, grow_mask=i)
wm = ai.integrate1d(inpainted, 2000, unit="q_nm^-1", method="splitpixel→˓", radial_range=(0,210))
print("method: %s npt_rad=%i grow=%i; R= %s"%(j, k, i,pyFAI.test.→˓utilstest.Rwp(wm,wo)))
method: csr npt_rad=512 grow=0; R= 3.16527395132method: csr npt_rad=512 grow=1; R= 2.90373554002method: csr npt_rad=512 grow=2; R= 2.7075280075method: csr npt_rad=512 grow=3; R= 2.65327421322method: csr npt_rad=512 grow=4; R= 2.61776326717method: csr npt_rad=512 grow=5; R= 2.57439873144method: csr npt_rad=512 grow=6; R= 2.54164759702method: csr npt_rad=512 grow=7; R= 2.54679849484method: csr npt_rad=512 grow=8; R= 2.53635706674method: csr npt_rad=512 grow=9; R= 2.52623386268method: csr npt_rad=1024 grow=0; R= 1.69183876823method: csr npt_rad=1024 grow=1; R= 1.31855606592method: csr npt_rad=1024 grow=2; R= 1.31247003017method: csr npt_rad=1024 grow=3; R= 1.29097440452method: csr npt_rad=1024 grow=4; R= 1.27074644319method: csr npt_rad=1024 grow=5; R= 1.27238306777method: csr npt_rad=1024 grow=6; R= 1.27167179838method: csr npt_rad=1024 grow=7; R= 1.26518530245method: csr npt_rad=1024 grow=8; R= 1.26533812218method: csr npt_rad=1024 grow=9; R= 1.26587569844method: csr npt_rad=2048 grow=0; R= 0.895867687266
112 Chapter 3. Tutorials
![Page 117: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/117.jpg)
pyFAI Documentation, Release 0.15.0a0
method: csr npt_rad=2048 grow=1; R= 0.645103411948method: csr npt_rad=2048 grow=2; R= 0.630137579053method: csr npt_rad=2048 grow=3; R= 0.624736974026method: csr npt_rad=2048 grow=4; R= 0.62869452797method: csr npt_rad=2048 grow=5; R= 0.628601472572method: csr npt_rad=2048 grow=6; R= 0.631538002653method: csr npt_rad=2048 grow=7; R= 0.629878287879method: csr npt_rad=2048 grow=8; R= 0.622824815248method: csr npt_rad=2048 grow=9; R= 0.631178231084method: csr npt_rad=4096 grow=0; R= 0.564353619636method: csr npt_rad=4096 grow=1; R= 0.399846196196method: csr npt_rad=4096 grow=2; R= 0.410612097165method: csr npt_rad=4096 grow=3; R= 0.410295214907method: csr npt_rad=4096 grow=4; R= 0.410335613233method: csr npt_rad=4096 grow=5; R= 0.406933039484method: csr npt_rad=4096 grow=6; R= 0.406117616454method: csr npt_rad=4096 grow=7; R= 0.404649982091method: csr npt_rad=4096 grow=8; R= 0.407870646779method: csr npt_rad=4096 grow=9; R= 0.41036433231
WARNING:pyFAI.splitBBoxCSR:Pixel splitting desactivated !
method: csr_nosplit npt_rad=512 grow=0; R= 3.84746010082method: csr_nosplit npt_rad=512 grow=1; R= 2.95385230424method: csr_nosplit npt_rad=512 grow=2; R= 2.67580240631method: csr_nosplit npt_rad=512 grow=3; R= 2.6126805269method: csr_nosplit npt_rad=512 grow=4; R= 2.58362811691method: csr_nosplit npt_rad=512 grow=5; R= 2.60564448801method: csr_nosplit npt_rad=512 grow=6; R= 2.58621310627method: csr_nosplit npt_rad=512 grow=7; R= 2.541826826method: csr_nosplit npt_rad=512 grow=8; R= 2.5206857231method: csr_nosplit npt_rad=512 grow=9; R= 2.52451588041
WARNING:pyFAI.splitBBoxCSR:Pixel splitting desactivated !
method: csr_nosplit npt_rad=1024 grow=0; R= 2.75213259282method: csr_nosplit npt_rad=1024 grow=1; R= 1.4384241414method: csr_nosplit npt_rad=1024 grow=2; R= 1.33379422417method: csr_nosplit npt_rad=1024 grow=3; R= 1.28940297956method: csr_nosplit npt_rad=1024 grow=4; R= 1.27720031756method: csr_nosplit npt_rad=1024 grow=5; R= 1.28777067352method: csr_nosplit npt_rad=1024 grow=6; R= 1.16986522429method: csr_nosplit npt_rad=1024 grow=7; R= 1.13872560834method: csr_nosplit npt_rad=1024 grow=8; R= 1.15033670027method: csr_nosplit npt_rad=1024 grow=9; R= 1.15867431745
WARNING:pyFAI.splitBBoxCSR:Pixel splitting desactivated !
method: csr_nosplit npt_rad=2048 grow=0; R= 2.79811477948method: csr_nosplit npt_rad=2048 grow=1; R= 1.22533548525method: csr_nosplit npt_rad=2048 grow=2; R= 1.12880254637method: csr_nosplit npt_rad=2048 grow=3; R= 1.02906086137method: csr_nosplit npt_rad=2048 grow=4; R= 0.991830558658method: csr_nosplit npt_rad=2048 grow=5; R= 0.907918584422method: csr_nosplit npt_rad=2048 grow=6; R= 0.841481199476method: csr_nosplit npt_rad=2048 grow=7; R= 0.805653872599method: csr_nosplit npt_rad=2048 grow=8; R= 0.786059385048method: csr_nosplit npt_rad=2048 grow=9; R= 0.765824492478
3.9. Inpainting missing data 113
![Page 118: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/118.jpg)
pyFAI Documentation, Release 0.15.0a0
WARNING:pyFAI.splitBBoxCSR:Pixel splitting desactivated !
method: csr_nosplit npt_rad=4096 grow=0; R= 2.66329347592method: csr_nosplit npt_rad=4096 grow=1; R= 1.19262995518method: csr_nosplit npt_rad=4096 grow=2; R= 1.15682781524method: csr_nosplit npt_rad=4096 grow=3; R= 1.15083356666method: csr_nosplit npt_rad=4096 grow=4; R= 1.12555533128method: csr_nosplit npt_rad=4096 grow=5; R= 1.10571482782method: csr_nosplit npt_rad=4096 grow=6; R= 1.06182288301method: csr_nosplit npt_rad=4096 grow=7; R= 1.0336445245method: csr_nosplit npt_rad=4096 grow=8; R= 0.992978393303method: csr_nosplit npt_rad=4096 grow=9; R= 0.962156509678
#Inpainting, best solution found:ai.reset()%time inpainted = ai.inpainting(img, mask=mask, poissonian=True, method="csr", npt_→˓rad=4096, grow_mask=5)fig, ax = subplots(1, 2, figsize=(12,5))jupyter.display(img=inpainted, label="Inpainted", ax=ax[0])jupyter.display(img=img_nomask-inpainted, label="Delta", ax=ax[1])ax[1].figure.colorbar(ax[1].images[0])
CPU times: user 3.84 s, sys: 740 ms, total: 4.58 sWall time: 1.49 s
<IPython.core.display.Javascript object>
<matplotlib.colorbar.Colorbar at 0x7f4ca4f16be0>
# Comparison of the inpained image with the original one:wm = ai.integrate1d(inpainted, 2000, unit="q_nm^-1", method="splitpixel", radial_→˓range=(0,210))wo = ai.integrate1d(img_nomask, 2000, unit="q_nm^-1", method="splitpixel", radial_→˓range=(0,210))ax = jupyter.plot1d(wm , label="inpainted")ax.plot(*wo, label="without_mask")ax.plot(wo.radial, wo.intensity-wm.intensity, label="delta")ax.legend()print("R= %s"%pyFAI.test.utilstest.Rwp(wm,wo))
<IPython.core.display.Javascript object>
R= 0.40783662849
Conclusion
Inpainting is one of the only solution to fill up the gaps in detector when Fourier analysis is needed. This tutorialexplains basically how this is possible using the pyFAI library and how to optimize the parameter set for inpainting.The result may greatly vary with detector position and tilt and the kind of signal (amorphous or more spotty).
print("Execution time: %.3fs"%(time.time()-start_time))
Execution time: 106.425s
114 Chapter 3. Tutorials
![Page 119: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/119.jpg)
CHAPTER 4
pyFAI scripts manual
While pyFAI is first and foremost a Python library to be used by developers, a set of scripts is provided to processa full diffraction experiment on the command line without knowing anything about Python. Those scripts can bedivided into 3 categories: pre-processing tools which prepare the dataset for the calibration tool. The calibration isthe determination of the geometry of the experimental setup using Debye-Scherrer rings of a reference compound(or calibrant). Finally a full dataset can be integrated using different tools targeted at different experiments.
Pre-processing tools:
• pyFAI-drawmask: tool for drawing a mask on top of an image
• pyFAI-average: tool for averaging/median/... filtering images (i.e. for dark current)
Calibration tools:
• pyFAI-calib: manually select the rings and refine the geometry
• pyFAI-recalib: automatic ring extraction to refine the geometry (deprecated: see “recalib” option inpyFAI-calib)
• MX-calibrate: Calibrate automatically a set of images taken at various detector distances
• check_calib: checks the calibration of an image at the sub-pixel level (deprecated: see “validate”option in pyFAI-calib)
Azimuthal integration tools:
• pyFAI-integrate: the graphical interface for integration (GUI)
• pyFAI-saxs: command line interface for small-angle scattering
• pyFAI-waxs: command line interface for powder difration
• diff_map: diffraction mapping & tomography tool (command line and GUI)
• diff_tomo: diffraction tomography tool (command line only)
115
![Page 120: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/120.jpg)
pyFAI Documentation, Release 0.15.0a0
Preprocessing tool: pyFAI-average
Purpose
This tool is used to average out a set of dark current images using mean or median filter (along the image stack).One can also reject outliers be specifying a cutoff (remove cosmic rays / zingers from dark)
It can also be used to merge many images from the same sample when using a small beam and reduce the spotty-ness of Debye-Scherrer rings. In this case the “max-filter” is usually recommended.
Options:
Usage: pyFAI-average [options] -o output.edf file1.edf file2.edf ...
positional arguments: FILE Files to be processed
optional arguments:
-h, --help show this help message and exit
-V, --version show program’s version number and exit
-o OUTPUT, --output OUTPUT Output/ destination of average image
-m METHOD, --method METHOD Method used for averaging, can be ‘mean’(default) or‘min’, ‘max’, ‘median’, ‘sum’, ‘quantiles’
-c CUTOFF, --cutoff CUTOFF Take the mean of the average +/- cutoff * std_dev.
-F FORMAT, --format FORMAT Output file/image format (by default EDF)
-d DARK, --dark DARK Dark noise to be subtracted
-f FLAT, --flat FLAT Flat field correction
-v, --verbose switch to verbose/debug mode
-q QUANTILES, --quantiles QUANTILES average out between two quantiles -q 0.20-0.90
Command u’pyFAI-average –help’ failed: [Errno 2] No such file or directory
Mask generation tool: pyFAI-drawmask
Purpose
Draw a mask, i.e. an image containing the list of pixels which are considered invalid (no scintillator, module gap,beam stop shadow, ...).
This will open a window and let you draw on the first image (provided) with different tools (brush, rectangleselection, ...). When you are finished, click on the “Save mask and quit” button on the bottom right of the window.The mask image is saved into filename-mask.edf. Optionally the script will print the number of pixel masked andthe intensity masked (as well on other files provided in input).
This user interface requires silx to be installed.
Usage: pyFAI-drawmask [options] file1.edf file2.edf ...
116 Chapter 4. pyFAI scripts manual
![Page 121: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/121.jpg)
pyFAI Documentation, Release 0.15.0a0
4.2. Mask generation tool: pyFAI-drawmask 117
![Page 122: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/122.jpg)
pyFAI Documentation, Release 0.15.0a0
Options:
--version show program’s version number and exit
-h, --help show help message and exit
Optionally the script will print the number of pixel masked and the intensity masked (as well on other files providedin input)
Command u’pyFAI-drawmask –help’ failed: [Errno 2] No such file or directory
Preprocessing tool: detector2nexus
Convert a complex detector definition (multiple modules, possibly in 3D) into a single NeXus detector definitiontogether with the mask (and much more in the future)
Purpose
Convert a detector to NeXus detector definition for pyFAI.
Usage:
detector2nexus [options] [options] -o nxs.h5
Options:
-h, --help show this help message and exit
-V, --version show program’s version number and exit
-o OUTPUT, --output OUTPUT Output nexus file, unless detector_name.h5
-n NAME, --name NAME name of the detector
-m MASK, --mask MASK mask corresponding to the detector
-D DETECTOR, --detector DETECTOR Base detector name (see documentationof pyFAI.detectors
-s SPLINEFILE, --splinefile SPLINEFILE Geometric distortion file from FIT2D
-dx DX, –x-corr DX Geometric correction for pilatus -dy DY, –y-corr DY Geometric correction forpilatus -p PIXEL, –pixel PIXEL
pixel size (comma separated): x,y
-S SHAPE, --shape SHAPE shape of the detector (comma separated): x,y
-d DARK, --dark DARK Dark noise to be subtracted
-f FLAT, --flat FLAT Flat field correction
-v, --verbose switch to verbose/debug mode
Command u’detector2nexus –help’ failed: [Errno 2] No such file or directory
118 Chapter 4. pyFAI scripts manual
![Page 123: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/123.jpg)
pyFAI Documentation, Release 0.15.0a0
Calibration tool: pyFAI-calib
Purpose
Calibrate the diffraction setup geometry based on Debye-Sherrer rings images without a priori knowledge of yoursetup. You will need to provide a calibrant or a “d-spacing” file containing the spacing of Miller plans in Angstrom(in decreasing order).
If you are using a standard calibrant, look at https://github.com/kif/pyFAI/tree/master/calibration or search in theAmerican Mineralogist database: [AMD] or in the [COD]. The –calibrant option is mandatory !
Calibrants available: Ni, CrOx, NaCl, Si_SRM640e, Si_SRM640d, Si_SRM640a, Si_SRM640b, Cr2O3, AgBh,Si_SRM640, CuO, PBBA, alpha_Al2O3, SI_SRM640c, quartz, C14H30O, cristobaltite, Si, LaB6, CeO2,LaB6_SRM660a, LaB6_SRM660b, LaB6_SRM660c, TiO2, ZnO, Al, Au
You will need in addition:
• The radiation energy (in keV) or its wavelength (in A)
• The description of the detector:
• it name or
• it’s pixel size or
• the spline file describing its distortion or
• the NeXus file describing the distortion
Many option are available among those:
• dark-current / flat field corrections
• Masking of bad regions
• reconstruction of missing region (module based detectors), see option -r
• Polarization correction
• Automatic desaturation (time consuming!)
• Intensity weighted least-squares refinements
The output of this program is a “PONI” file containing the detector description and the 6 refined parameters(distance, center, rotation) and wavelength. An 1D and 2D diffraction patterns are also produced. (.dat and .azimfiles)
Usage:
pyFAI-calib [options] -w 1 -D detector -c calibrant imagefile.edf
Options:
-h, --help show this help message and exit
-V, --version show program’s version number and exit
-o FILE, --out FILE Filename where processed image is saved
-v, --verbose switch to debug/verbose mode
-c FILE, --calibrant FILE Calibrant name or file containing d-spacing of the refer-ence sample (MANDATORY, case sensitive !)
-w WAVELENGTH, --wavelength WAVELENGTH wavelength of the X-Raybeam in Angstrom. Mandatory
4.4. Calibration tool: pyFAI-calib 119
![Page 124: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/124.jpg)
pyFAI Documentation, Release 0.15.0a0
-e ENERGY, --energy ENERGY energy of the X-Ray beam in keV(hc=12.398419292keV.A).
-P POLARIZATION_FACTOR, --polarization POLARIZATION_FACTORpolarization factor, from -1 (vertical) to +1 (horizontal), defaultis None (no correction), synchrotrons are around 0.95
-i FILE, --poni FILE file containing the diffraction parameter (poni-file). MANDA-TORY for pyFAI-recalib!
-b BACKGROUND, --background BACKGROUND Automatic background sub-traction if no value are provided
-d DARK, --dark DARK list of comma separated dark images to average and sub-tract
-f FLAT, --flat FLAT list of comma separated flat images to average and divide
-s SPLINE, --spline SPLINE spline file describing the detector distortion
-D DETECTOR_NAME, --detector DETECTOR_NAME Detector name (insteadof pixel size+spline)
-m MASK, --mask MASK file containing the mask (for image reconstruction)
-n NPT, --pt NPT file with datapoints saved. Default: basename.npt
--filter FILTER select the filter, either mean(default), max or median
-l DISTANCE, --distance DISTANCE sample-detector distance in millimeter. De-fault: 100mm
--dist DIST sample-detector distance in meter. Default: 0.1m
--poni1 PONI1 poni1 coordinate in meter. Default: center of detector
--poni2 PONI2 poni2 coordinate in meter. Default: center of detector
--rot1 ROT1 rot1 in radians. default: 0
--rot2 ROT2 rot2 in radians. default: 0
--rot3 ROT3 rot3 in radians. default: 0
--fix-dist fix the distance parameter
--free-dist free the distance parameter. Default: Activated
--fix-poni1 fix the poni1 parameter
--free-poni1 free the poni1 parameter. Default: Activated
--fix-poni2 fix the poni2 parameter
--free-poni2 free the poni2 parameter. Default: Activated
--fix-rot1 fix the rot1 parameter
--free-rot1 free the rot1 parameter. Default: Activated
--fix-rot2 fix the rot2 parameter
--free-rot2 free the rot2 parameter. Default: Activated
--fix-rot3 fix the rot3 parameter
--free-rot3 free the rot3 parameter. Default: Activated
--fix-wavelength fix the wavelength parameter. Default: Activated
--free-wavelength free the wavelength parameter. Default: Deactivated
--tilt Allow initially detector tilt to be refined (rot1, rot2, rot3). De-fault: Activated
120 Chapter 4. pyFAI scripts manual
![Page 125: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/125.jpg)
pyFAI Documentation, Release 0.15.0a0
--no-tilt Deactivated tilt refinement and set all rotation to 0
--saturation SATURATION consider all pixel>max*(1-saturation) as saturated andreconstruct them, default: 0 (deactivated)
--weighted weight fit by intensity, by default not.
--npt NPT_1D Number of point in 1D integrated pattern, Default: 1024
--npt-azim NPT_2D_AZIM Number of azimuthal sectors in 2D integrated images.Default: 360
--npt-rad NPT_2D_RAD Number of radial bins in 2D integrated images. Default:400
--unit UNIT Valid units for radial range: 2th_deg, 2th_rad, q_nm^-1, q_A^-1,r_mm. Default: 2th_deg
--no-gui force the program to run without a Graphical interface
--no-interactive force the program to run and exit without prompting for refine-ments
-r, --reconstruct Reconstruct image where data are masked or <0 (for Pilatus de-tectors or detectors with modules)
-g GAUSSIAN, --gaussian GAUSSIAN Size of the gaussian kernel. Size of the gap(in pixels) between two consecutive rings, by default 100 In-crease the value if the arc is not complete; decrease the value ifarcs are mixed together.
--square Use square kernel shape for neighbor search instead of diamondshape
-p PIXEL, --pixel PIXEL size of the pixel in micron
Tips & Tricks
PONI-files are ASCII files and each new refinement adds an entry in the file. So if you are unhappy with the laststep, just edit this file and remove the last entry (time-stamps will help you).
Example of usage:
Command u’pyFAI-calib –help’ failed: [Errno 2] No such file or directory
Pilatus 1M image of Silver Behenate taken at ESRF-BM26:
pyFAI-calib -D Pilatus1M -c AgBh -r -w 1.0 test/testimages/Pilatus1M.edf
We use the parameter -r to reconstruct the missing part between the modules of the Pilatus detector.
Half a FReLoN CCD image of Lantanide hexaboride taken at ESRF-ID11:
pyFAI-calib -s test/testimages/halfccd.spline -c LaB6 -w 0.3 test/testimages/→˓halfccd.edf -g 250
This image is rather spotty. We need to blur a lot to get the continuity of the rings. This is achieved by the -gparameter. While the sample is well diffracting and well known, the wavelength has been guessed. One shouldrefine the wavelength when the peaks extracted are correct
All those images are part of the test-suite of pyFAI. To download them from internet, run
4.4. Calibration tool: pyFAI-calib 121
![Page 126: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/126.jpg)
pyFAI Documentation, Release 0.15.0a0
python setup.py build test
Downloaded test images are located in tests/testimages
Calibration tool: pyFAI-recalib
pyFAI-recalib is now obsolete. All feature provided by it are now available as part of pyFAI-calib.
Command u’pyFAI-recalib –help’ failed: [Errno 2] No such file or directory
Calibration tool: check_calib
Purpose
Check_calib is a deprecated tool aiming at validating both the geometric calibration and everything else like flat-field correction, distortion correction, at a sub-pixel level. Please use the validate, validate2 and chiplot commandsin pyFAI-calib, during the refinement process to obtain the same output with more options.
Command u’check_calib –help’ failed: [Errno 2] No such file or directory
Calibration tool: MX-calibrate
Purpose
Calibrate automatically a set of frames taken at various sample-detector distance.
This tool has been developed for ESRF MX-beamlines where an acceptable calibration is usually present is theheader of the image. PyFAI reads it and does a “recalib” on each of them before exporting a linear regression ofall parameters versus this distance.
Most standard calibrants are directly installed together with pyFAI. If you prefer using your own, you can providea “d-spacing” file containing the spacing of Miller plans in Angstrom (in decreasing order). Most crystal powdersused for calibration are available in the American Mineralogist database [AMD] or in the [COD].
Usage:
MX-Calibrate -w 1.54 -c CeO2 file1.cbf file2.cbf ...
Options:
usage: MX-Calibrate -w 1.54 -c CeO2 file1.cbf file2.cbf ...
Calibrate automatically a set of frames taken at various sample-detector distance. Return the linear regression ofthe fit in funtion of the sample- setector distance.
positional arguments: FILE List of files to calibrate
optional arguments:
-h, --help show this help message and exit
-V, --version show program’s version number and exit
-v, --verbose switch to debug/verbose mode
122 Chapter 4. pyFAI scripts manual
![Page 127: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/127.jpg)
pyFAI Documentation, Release 0.15.0a0
-c FILE, --calibrant FILE file containing d-spacing of the calibrant reference sample(MANDATORY)
-w WAVELENGTH, --wavelength WAVELENGTH wavelength of the X-Ray beam inAngstrom
-e ENERGY, --energy ENERGY energy of the X-Ray beam in keV(hc=12.398419292keV.A)
-P POLARIZATION_FACTOR, --polarization POLARIZATION_FACTORpolarization factor, from -1 (vertical) to +1 (horizontal), defaultis 0, synchrotrons are around 0.95
-b BACKGROUND, --background BACKGROUND Automatic background subtractionif no value are provided
-d DARK, --dark DARK list of dark images to average and subtract
-f FLAT, --flat FLAT list of flat images to average and divide
-s SPLINE, --spline SPLINE spline file describing the detector distortion
-p PIXEL, --pixel PIXEL size of the pixel in micron
-D DETECTOR_NAME, --detector DETECTOR_NAME Detector name (instead ofpixel size+spline)
-m MASK, --mask MASK file containing the mask (for image reconstruction)
--filter FILTER select the filter, either mean(default), max or median
--saturation SATURATION consider all pixel>max*(1-saturation) as saturated and recon-struct them
-r MAX_RINGS, --ring MAX_RINGS maximum number of rings to extract
--weighted weight fit by intensity
-l DISTANCE, --distance DISTANCE sample-detector distance in millimeter
--tilt Allow initially detector tilt to be refined (rot1, rot2, rot3). Default:Activated
--no-tilt Deactivated tilt refinement and set all rotation to 0
--dist DIST sample-detector distance in meter
--poni1 PONI1 poni1 coordinate in meter
--poni2 PONI2 poni2 coordinate in meter
--rot1 ROT1 rot1 in radians
--rot2 ROT2 rot2 in radians
--rot3 ROT3 rot3 in radians
--fix-dist fix the distance parameter
--free-dist free the distance parameter
--fix-poni1 fix the poni1 parameter
--free-poni1 free the poni1 parameter
--fix-poni2 fix the poni2 parameter
--free-poni2 free the poni2 parameter
--fix-rot1 fix the rot1 parameter
--free-rot1 free the rot1 parameter
--fix-rot2 fix the rot2 parameter
4.7. Calibration tool: MX-calibrate 123
![Page 128: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/128.jpg)
pyFAI Documentation, Release 0.15.0a0
--free-rot2 free the rot2 parameter
--fix-rot3 fix the rot3 parameter
--free-rot3 free the rot3 parameter
--fix-wavelength fix the wavelength parameter
--free-wavelength free the wavelength parameter
--no-gui force the program to run without a Graphical interface
--gui force the program to run with a Graphical interface
--no-interactive force the program to run and exit without prompting for refinements
--interactive force the program to prompt for refinements
--peak-picker PEAKPICKER Uses the ‘massif’, ‘blob’ or ‘watershed’ peak-picker algo-rithm (default: blob)
This tool has been developed for ESRF MX-beamlines where an acceptable calibration is usually present is theheader of the image. PyFAI reads it and does a “recalib” on each of them before exporting a linear regression ofall parameters versus this distance.
Example:
Command u’MX-calibrate –help’ failed: [Errno 2] No such file or directory
Integration tool: pyFAI-integrate
Purpose
PyFAI-integrate is a graphical interface (based on Python/Qt4) to perform azimuthal integration on a set of files.It exposes most of the important options available within pyFAI and allows you to select a GPU (or an openCLplatform) to perform the calculation on.
Usage
pyFAI-integrate [options] file1.edf file2.edf ...
Options:
--version show program’s version number and exit
-h, --help show help message and exit
-v, --verbose switch to verbose/debug mode
-o OUTPUT, --output=OUTPUT Directory or file where to store the output data
Tips & Tricks:
PyFAI-integrate saves all parameters in a .azimint.json (hidden) file. This JSON file is an ascii file which can beedited and used to configure online data analysis using the LImA plugin of pyFAI.
Nota: there is bug in debian6 making the GUI crash (to be fixed inside pyqt) http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=697348
124 Chapter 4. pyFAI scripts manual
![Page 129: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/129.jpg)
pyFAI Documentation, Release 0.15.0a0
4.8. Integration tool: pyFAI-integrate 125
![Page 130: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/130.jpg)
pyFAI Documentation, Release 0.15.0a0
Example:
Command u’pyFAI-integrate –help’ failed: [Errno 2] No such file or directory
Integration tool: diff_map
Purpose
Azimuthal integration for diffraction imaging
Diffraction mapping is an imaging experiment where 2D diffraction patterns are recorded while performing a 2Dscan along two axes, one slower and the other fastest.
Diff_map provides a Graphical User Interface (based on top of PyQt, pyFAI and h5py) which allows the reductionof this 4D dataset into a 3D dataset containing the two dimension of movement and the many diffraction angles(the output can be q-space for PDF-CT).
On the left-hand side, the user can select a bunch of files to be processed. For now, any image format supportedby FabIO is possible, including multi-frame images, but not ye NeXus files (work ongoing).
On the right-hand side, the motor range can be specified togeather with their names. The diffraction parameterscan be setup in a similar way to pyFAI-integrate. The output name can also be specified.
The processing is launched using the Run button which opens a matplotlib figure to display the plot of the diffrac-tion pattern and of the map image under construction. During this processing, one can select a scatering range tohighlight the regions of interest.
Further analysis can be performed on the resulting dataset using the PyMca roitool where the 1d dataset has to beselected as last dimension. The result file aims at NeXus compliance.
This tool can be used for tomography experiments if one considers the slow scan direction as the rotation.
The user interface can be disabled to allow scripting interface and providing a JSON configuration file (or all theoptions).
126 Chapter 4. pyFAI scripts manual
![Page 131: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/131.jpg)
pyFAI Documentation, Release 0.15.0a0
4.9. Integration tool: diff_map 127
![Page 132: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/132.jpg)
pyFAI Documentation, Release 0.15.0a0
Usage:
diff_map [options] imagefiles*
positional arguments: FILE List of files to integrate
optional arguments:
-h, --help show this help message and exit
-V, --version show program’s version number and exit
-o FILE, --output FILE HDF5 File where processed map will be saved
-v, --verbose switch to verbose/debug mode, defaut: quiet
-P FILE, --prefix FILE Prefix or common base for all files
-e EXTENSION, --extension EXTENSION Process all files with this extension
-t FAST, --fast FAST number of points for the fast motion. Mandatory without GUI
-r SLOW, --slow SLOW number of points for slow motion. Mandatory without GUI
-c NPT_RAD, --npt NPT_RAD number of points in diffraction powder pattern, Mandatorywithout GUI
-d FILE, --dark FILE list of dark images to average and subtract
-f FILE, --flat FILE list of flat images to average and divide
-m FILE, --mask FILE file containing the mask, no mask by default
-p FILE, --poni FILE file containing the diffraction parameter (poni-file), Mandatory with-out GUI
-O OFFSET, --offset OFFSET do not process the first files
-g, --gpu process using OpenCL on GPU
-S, --stats show statistics at the end
--gui Use the Graphical User Interface
--no-gui Do not use the Graphical User Interface
--config CONFIG provide a JSON configuration file
Bugs:
1. If the number of files is too large, use double quotes “*.edf”
2. There is a known bug on Debian7 where importing a large number of file can take much longer than theintegration itself: consider passing files in the command line
Command u’diff_map –help’ failed: [Errno 2] No such file or directory
Integration tool: diff_tomo
Purpose
Azimuthal integration for diffraction tomography.
Diffraction tomography is an experiment where 2D diffraction patterns are recorded while performing a 2D scan,one (the slowest) in rotation around the sample center and the other (the fastest) along a translation through thesample. Diff_tomo is a script (based on pyFAI and h5py) which allows the reduction of this 4D dataset into a 3Ddataset containing the rotations angle (hundreds), the translation step (hundreds) and the many diffraction angles
128 Chapter 4. pyFAI scripts manual
![Page 133: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/133.jpg)
pyFAI Documentation, Release 0.15.0a0
(thousands). The resulting dataset can be opened using PyMca roitool where the 1d dataset has to be selected aslast dimension. This file is not (yet) NeXus compliant.
This tool can be used for mapping experiments if one considers the slow scan direction as the rotation, but a toolnamed diff_map operates in a similar way, provides a Graphical interface and is more flexible.
tips: If the number of files is too large, use double quotes around “*.edf”
Usage:
diff_tomo [options] -p ponifile imagefiles*
Options:
-h, --help show this help message and exit
-V, --version show program’s version number and exit
-o FILE, --output FILE HDF5 File where processed sinogram was saved, by defaultdiff_tomo.h5
-v, --verbose switch to verbose/debug mode, defaut: quiet
-P FILE, --prefix FILE Prefix or common base for all files
-e EXTENSION, --extension EXTENSION Process all files with this extension
-t NTRANS, --nTrans NTRANS number of points in translation. Mandatory
-r NROT, --nRot NROT number of points in rotation. Mandatory
-c NDIFF, --nDiff NDIFF number of points in diffraction powder pattern, Mandatory
-d FILE, --dark FILE list of dark images to average and subtract
-f FILE, --flat FILE list of flat images to average and divide
-m FILE, --mask FILE file containing the mask, no mask by default
-p FILE, --poni FILE file containing the diffraction parameter (poni-file), Manda-tory
-O OFFSET, --offset OFFSET do not process the first files
-g, --gpu process using OpenCL on GPU
-S, --stats show statistics at the end
Most of those options are mandatory to define the structure of the dataset.
Command u’diff_tomo –help’ failed: [Errno 2] No such file or directory
Integration tool: pyFAI-saxs
Purpose
Azimuthal integration for SAXS users.
pyFAI-saxs is the SAXS script of pyFAI that allows data reduction (azimuthal integration) for Small Angle Scat-tering with output axis in q space.
4.11. Integration tool: pyFAI-saxs 129
![Page 134: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/134.jpg)
pyFAI Documentation, Release 0.15.0a0
Usage:
pyFAI-saxs -p=param.poni -w1.54 file.edf file2.edf file3.edf
Options:
-h, --help show this help message and exit
-v, --version show program’s version number and exit
-p PONIFILE PyFAI parameter file (.poni)
-n NPT, --npt NPT Number of points in radial dimension
-w WAVELENGTH, --wavelength WAVELENGTH wavelength of the X-Ray beam inAngstrom
-e ENERGY, --energy ENERGY energy of the X-Ray beam in keV(hc=12.398419292keV.A)
-u DUMMY, --dummy DUMMY dummy value for dead pixels
-U DELTA_DUMMY, --delta_dummy DELTA_DUMMY delta dummy value
-m MASK, --mask MASK name of the file containing the mask image
-d DARK, --dark DARK name of the file containing the dark current
-f FLAT, --flat FLAT name of the file containing the flat field
-P POLARIZATION_FACTOR, --polarization POLARIZATION_FACTORPolarization factor, from -1 (vertical) to +1 (horizontal), defaultis None for no correction, synchrotrons are around 0.95
--error-model ERROR_MODEL Error model to use. Currently on ‘poisson’ is imple-mented
--unit UNIT unit for the radial dimension: can be q_nm^-1, q_A^-1, 2th_deg,2th_rad or r_mm
--ext EXT extension of the regrouped filename (.dat)
--method METHOD Integration method
Example:
Command u’pyFAI-saxs –help’ failed: [Errno 2] No such file or directory
Integration tool: pyFAI-waxs
Purpose
Azimuthal integration for powder diffraction.
pyFAI-waxs is the script of pyFAI that allows data reduction (azimuthal integration) for Wide Angle Scattering toproduce X-Ray Powder Diffraction Pattern with output axis in 2-theta space.
Usage:
pyFAI-waxs -p param.poni [options] file1.edf file2.edf ...
130 Chapter 4. pyFAI scripts manual
![Page 135: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/135.jpg)
pyFAI Documentation, Release 0.15.0a0
Options:
-h, --help show this help message and exit
-v, --version show program’s version number and exit
-p PONIFILE PyFAI parameter file (.poni)
-n NPT, --npt NPT Number of points in radial dimension
-w WAVELENGTH, --wavelength WAVELENGTH wavelength of the X-Raybeam in Angstrom
-e ENERGY, --energy ENERGY energy of the X-Ray beam in keV(hc=12.398419292keV.A)
-u DUMMY, --dummy DUMMY dummy value for dead pixels
-U DELTA_DUMMY, --delta_dummy DELTA_DUMMY delta dummy value
-m MASK, --mask MASK name of the file containing the mask image
-d DARK, --dark DARK name of the file containing the dark current
-f FLAT, --flat FLAT name of the file containing the flat field
-P POLARIZATION_FACTOR, --polarization POLARIZATION_FACTORPolarization factor, from -1 (vertical) to +1 (horizontal), defaultis None for no correction, synchrotrons are around 0.95
--error-model ERROR_MODEL Error model to use. Currently on ‘poisson’ is im-plemented
--unit UNIT unit for the radial dimension: can be q_nm^-1, q_A^-1, 2th_deg,2th_rad or r_mm
--ext EXT extension of the regrouped filename (.xy)
--method METHOD Integration method
--multi Average out all frame in a file before integrating
--average AVERAGE Method for averaging out: can be ‘mean’ (default), ‘min’,‘max’ or ‘median
--do-2D Perform 2D integration in addition to 1D
pyFAI-waxs is the script of pyFAI that allows data reduction (azimuthal integration) for Wide Angle Scattering toproduce X-Ray Powder Diffraction Pattern with output axis in 2-theta space.
Example:
Command u’pyFAI-waxs –help’ failed: [Errno 2] No such file or directory
4.12. Integration tool: pyFAI-waxs 131
![Page 136: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/136.jpg)
pyFAI Documentation, Release 0.15.0a0
132 Chapter 4. pyFAI scripts manual
![Page 137: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/137.jpg)
CHAPTER 5
Design of the Python Fast Azimuthal Integration library
Author: Jérôme Kieffer
Date: 18/12/2014
Keywords: Design
Target: Developers interested in using the library
Reference: API documentation
Design of the Python Fast Azimuthal Integrator
Author: Jérôme Kieffer
Date: 20/03/2015
Keywords: Design
Target: Developers interested in using the library
Reference: API documentation
Abstract
The core part of pyFAI is the AzimuthalIntegator objects, named ai hereafter. This document describes the twoimportant methods of the class, how it is related to Detector, Geometry, and integration engines.
One of the core idea is to have a complete representation of the geometry and perform the azimuthal integrationas a single geometrical re-binning which take into account all effects like:
• Detector distortion
• Polar transformation
• assignment to the output space
This document focuses on the core of pyFAI while peripheral code dealing with graphical user interfaces, imageanalysis online data analysis integration are not covered.
133
![Page 138: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/138.jpg)
pyFAI Documentation, Release 0.15.0a0
AzimuthalIntegrator
This class is the core of pyFAI, and it is the only one likely to be used by external developers/users. It is usuallyinstantiated via a function of the module to load a poni-file:
>>> import pyFAI>>> ai = pyFAI.load("Pilatus1M.poni")>>> print(ai)
Detector Detector Spline= None PixelSize= 1.720e-04, 1.720e-04 m
SampleDetDist= 1.583231e+00m PONI= 3.341702e-02, 4.122778e-02m rot1=0.→˓006487 rot2= 0.007558 rot3= 0.000000 rad
DirectBeamDist= 1583.310mm Center: x=179.981, y=263.859 pix Tilt=0.571→˓deg tiltPlanRotation= 130.640 deg
As one can see, the ai contains the detector geometry (type, pixel size, distortion) as well as the geometry of theexperimental setup. The geometry is given in two equivalent forms: the internal representation of pyFAI (secondline) and the one used by FIT2D.
The ai is responsible for azimuthal integration, either the integration along complete ring, called full-integration,obtained via ai.integrate1d method. The sector-wise integration is obtained via the ai.integrate2d method. The op-tions for those two methods are really similar and differ only by the parameters related to the azimuthal dimensionof the averaging for ai.integrate2d.
Azimuthal integration methods
Both integration method take as first argument the image coming from the detector as a numpy array. This is theonly mandatory parameter.
Important parameters are the number of bins in radial and azimuthal dimensions. Other parameters are the pre-processing information like dark and flat pixel wise correction (as array), the polarization factor and the solid-anglecorrection to be applied.
Because multiple radial output space are possible (q, r, 2theta) each with multiple units, if one wants to avoidinterpolation, it is important to export directly the data in the destination space, specifying the unit=”2th_deg” or“q_nm^-1”
Many more option exists, please refer to the documentation of AzimuthalIntegration integrate
The AzimuthalIntegration class inherits from the Geometry class and hold references to configured rebinningengines.
Geometry
The Geometry class contains a reference to the detector (composition) and the logic to calculate the position inspace of the various pixels. All arrays in the class are cached and calculated on demand.
The Geometry class relies on the detector to provide the pixel position in space and subsequently transforms itin 2theta coordinates, or q, chi, r ... This can either be performed in the class itself or by calling function in theparallel implemented Cython module _geometry. Those transformation could be GPU-ized in the future.
Detector
PyFAI deals only with area detector, indexed in 2 dimension but can handle pixel located in a 3D space.
The pyFAI.detectors module contains the master Detector class which is capable of describing any detector. About40 types of detectors, inheriting and specializing the Detector class are provided, offering convenient access tomost commercial detectors. A factory is provided to easily instantiate a detector from its name.
134 Chapter 5. Design of the Python Fast Azimuthal Integration library
![Page 139: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/139.jpg)
pyFAI Documentation, Release 0.15.0a0
A detector class is responsible for two main tasks:
• provide the coordinate in space of any pixel position (center, corner, ...)
• Handle the mask: some detector feature automatic mask calculation (i.e. module based detectors).
The distortion of the detector is handled here and could be GPU-ized in the future.
Rebinning engines
Once the geometry (radial and azimuthal coordinates) calculated for every pixel on the detector, the image fromthe detector is rebinned into the output space. Two types of rebinning engines exists:
• Histograms
They take each single pixel from the image and transfer it to the destination bin, like histogramsdo. This family of algorithms is rather easy to implement and provides good single threadedperformances, but it is hard to parallelize (efficiently) due to the need of atomic operations.
• Sparse matrix multiplication
By recording where every single ends one can transform the previous histogram into a largesparse matrix multiplication which is either stored as a Look-Up Table (actually an array ofstruct, also called LIL) or more efficiently in the CSR format. Those rebinning engines aretrivially parallel and provide the best performances.
Pixel splitting
Three levels of pixel splitting schemes are available within pyFAI:
• No splitting
The whole intensity is assigned to the center of the pixel and rebinned using a simple histogram
• Bounding box pixel splitting
The pixel is abstracted by a box surrounding it with, making calculation easier but blurring a bitthe image
• Tight pixel splitting
The pixel is represented by its actual corner position, offering a very precise positioning in space.
The main issue with pixel splitting arose from 2D integration and the handling of pixel laying on the chi-discontinuity.
5.1. Design of the Python Fast Azimuthal Integrator 135
![Page 140: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/140.jpg)
pyFAI Documentation, Release 0.15.0a0
136 Chapter 5. Design of the Python Fast Azimuthal Integration library
![Page 141: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/141.jpg)
CHAPTER 6
pyFAI API
This chapter describes the programming interface of pyFAI, so what you can expect after having launched Jupyternotebook (or ipython) and typed:
import pyFAI
The most important class is AzimuthalIntegrator which is an object containing both the geometry (it inherits fromGeometry, another class) and exposes important methods (functions) like integrate1d and integrate2d.
pyFAI Package
pyFAI.__init__.benchmarks(*arg, **kwarg)Run the integrated benchmarks.
See the documentation of pyFAI.benchmark.run_benchmark
pyFAI.__init__.tests(deprecation=False)Runs the test suite of the installed version
Parameters deprecation – enable/disables deprecation warning in the tests
average Module
Utilities, mainly for image treatment
exception pyFAI.average.AlgorithmCreationErrorBases: exceptions.RuntimeError
Exception returned if creation of an ImageReductionFilter is not possible
class pyFAI.average.AverageBases: object
Process images to generate an average using different algorithms.
__init__()Constructor
137
![Page 142: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/142.jpg)
pyFAI Documentation, Release 0.15.0a0
add_algorithm(algorithm)Defines another algorithm which will be computed on the source.
Parameters algorithm (ImageReductionFilter) – An averaging algorithm.
get_counter_frames()Returns the number of frames used for the process.
Return type int
get_fabio_images()Returns source images as fabio images.
Return type list(fabio.fabioimage.FabioImage)
get_image_reduction(algorithm)Returns the result of an algorithm. The process must be already done.
Parameters algorithm (ImageReductionFilter) – An averaging algorithm
Return type numpy.ndarray
process()Process source images to all defined averaging algorithms defined using defined parameters. To accessto the results you have to define a writer (AverageWriter). To follow the process forward you have todefine an observer (AverageObserver).
set_correct_flat_from_dark(correct_flat_from_dark)Defines if the dark must be applied on the flat.
Parameters correct_flat_from_dark (bool) – If true, the dark is applied.
set_dark(dark_list)Defines images used as dark.
Parameters dark_list (list) – List of dark used
set_flat(flat_list)Defines images used as flat.
Parameters flat_list (list) – List of dark used
set_images(image_list)Defines the set set of source images to used to process an average.
Parameters image_list (list) – List of filename, numpy arrays, fabio images used assource for the computation.
set_monitor_name(monitor_name)Defines the monitor name used to correct images before processing the average. This monitor must bepart of the file header, else the image is skipped.
Parameters monitor_name (str) – Name of the monitor available on the header file
set_observer(observer)Set an observer to the average process.
Parameters observer (AverageObserver) – An observer
set_pixel_filter(threshold, minimum, maximum)Defines the filter applied on each pixels of the images before processing the average.
Parameters
• threshold – what is the upper limit? all pixel > max*(1-threshold) are discareded.
• minimum – minimum valid value or True
• maximum – maximum valid value
set_writer(writer)Defines the object write which will be used to store the result.
138 Chapter 6. pyFAI API
![Page 143: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/143.jpg)
pyFAI Documentation, Release 0.15.0a0
Parameters writer (AverageWriter) – The writer to use.
class pyFAI.average.AverageDarkFilter(filter_name, cut_off, quantiles)Bases: pyFAI.average.ImageStackFilter
Filter based on the algorithm of average_dark
TODO: Must be split according to each filter_name, and removed
__init__(filter_name, cut_off, quantiles)
get_parameters()Return a dictionary containing filter parameters
name
class pyFAI.average.AverageObserverBases: object
algorithm_finished(algorithm)Called when an algorithm is finished
algorithm_started(algorithm)Called when an algorithm is started
frame_processed(algorithm, frame_index, frames_count)Called after providing a frame to an algorithm
image_loaded(fabio_image, image_index, images_count)Called when an input image is loaded
process_finished()Called when the full process is finished
process_started()Called when the full processing is started
result_processing(algorithm)Called before the result of an algorithm is computed
class pyFAI.average.AverageWriterInterface for using writer in Average process.
close()Close the writer. Must not be used anymore.
write_header(merged_files, nb_frames, monitor_name)Write the header of the average
Parameters
• merged_files (list) – List of files used to generate this output
• nb_frames (int) – Number of frames used
• monitor_name (str) – Name of the monitor used. Can be None.
write_reduction(algorithm, data)Write one reduction
Parameters
• algorithm (ImageReductionFilter) – Algorithm used
• data (object) – Data of this reduction
class pyFAI.average.ImageAccumulatorFilterBases: pyFAI.average.ImageReductionFilter
Filter applied in a set of images in which it is possible to reduce data step by step into a single mergedimage.
6.2. average Module 139
![Page 144: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/144.jpg)
pyFAI Documentation, Release 0.15.0a0
add_image(image)Add an image to the filter.
Parameters image (numpy.ndarray) – image to add
get_result()Get the result of the filter.
Returns result filter
Return type numpy.ndarray
init(max_images=None)
class pyFAI.average.ImageReductionFilterBases: object
Generic filter applied in a set of images.
add_image(image)Add an image to the filter.
Parameters image (numpy.ndarray) – image to add
get_parameters()Return a dictionary containing filter parameters
Return type dict
get_result()Get the result of the filter.
Returns result filter
init(max_images=None)Initialize the filter before using it.
Parameters max_images (int) – Max images supported by the filter
class pyFAI.average.ImageStackFilterBases: pyFAI.average.ImageReductionFilter
Filter creating a stack from all images and computing everything at the end.
add_image(image)Add an image to the filter.
Parameters image (numpy.ndarray) – image to add
get_result()
init(max_images=None)
class pyFAI.average.MaxAveragingBases: pyFAI.average.ImageAccumulatorFilter
name = ‘max’
class pyFAI.average.MeanAveragingBases: pyFAI.average.SumAveraging
get_result()
name = ‘mean’
class pyFAI.average.MinAveragingBases: pyFAI.average.ImageAccumulatorFilter
name = ‘min’
140 Chapter 6. pyFAI API
![Page 145: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/145.jpg)
pyFAI Documentation, Release 0.15.0a0
exception pyFAI.average.MonitorNotFoundBases: exceptions.Exception
Raised when monitor information in not found or is not valid.
class pyFAI.average.MultiFilesAverageWriter(file_name_pattern, file_format,dry_run=False)
Bases: pyFAI.average.AverageWriter
Write reductions into multi files. File headers are duplicated.
__init__(file_name_pattern, file_format, dry_run=False)
Parameters
• file_name_pattern (str) – File name pattern for the output files. If it con-tains “{method_name}”, it is updated for each reduction writing with the name of thereduction.
• file_format (str) – File format used. It is the default extension file.
• dry_run (bool) – If dry_run, the file is created on memory but not saved on the filesystem at the end
close()Close the writer. Must not be used anymore.
get_fabio_image(algorithm)Get the constructed fabio image
Return type fabio.fabioimage.FabioImage
write_header(merged_files, nb_frames, monitor_name)
write_reduction(algorithm, data)
class pyFAI.average.SumAveragingBases: pyFAI.average.ImageAccumulatorFilter
name = ‘sum’
pyFAI.average.average_dark(lstimg, center_method=’mean’, cutoff=None, quantiles=(0.5,0.5))
Averages a serie of dark (or flat) images. Centers the result on the mean or the median ... but averages allframes within cutoff*std
Parameters
• lstimg – list of 2D images or a 3D stack
• center_method (str) – is the center calculated by a “mean”, “median”, “quantile”,“std”
• cutoff (float or None) – keep all data where (I-center)/std < cutoff
• quantiles (tuple(float, float) or None) – 2-tuple of floats average outdata between the two quantiles
Returns 2D image averaged
pyFAI.average.average_images(listImages, output=None, threshold=0.1, minimum=None,maximum=None, darks=None, flats=None, filter_=’mean’,correct_flat_from_dark=False, cutoff=None, quantiles=None,fformat=’edf’, monitor_key=None)
Takes a list of filenames and create an average frame discarding all saturated pixels.
Parameters
• listImages – list of string representing the filenames
• output – name of the optional output file
6.2. average Module 141
![Page 146: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/146.jpg)
pyFAI Documentation, Release 0.15.0a0
• threshold – what is the upper limit? all pixel > max*(1-threshold) are discareded.
• minimum – minimum valid value or True
• maximum – maximum valid value
• darks – list of dark current images for subtraction
• flats – list of flat field images for division
• filter – can be “min”, “max”, “median”, “mean”, “sum”, “quantiles” (de-fault=’mean’)
• correct_flat_from_dark – shall the flat be re-corrected ?
• cutoff – keep all data where (I-center)/std < cutoff
• quantiles – 2-tuple containing the lower and upper quantile (0<q<1) to average out.
• fformat – file format of the output image, default: edf
• str (monitor_key) – Key containing the monitor. Can be none.
Returns filename with the data or the data ndarray in case format=None
pyFAI.average.bounding_box(img)Tries to guess the bounding box around a valid massif
Parameters img – 2D array like
Returns 4-typle (d0_min, d1_min, d0_max, d1_max)
pyFAI.average.common_prefix(string_list)Return the common prefix of a list of strings
TODO: move it into utils package
Parameters string_list (list(str)) – List of strings
Return type str
pyFAI.average.create_algorithm(filter_name, cut_off=None, quantiles=None)Factory to create algorithm according to parameters
Parameters
• cutoff (float or None) – keep all data where (I-center)/std < cutoff
• quantiles (tuple(float, float) or None) – 2-tuple of floats average outdata between the two quantiles
Returns An algorithm
Return type ImageReductionFilter
Raises AlgorithmCreationError – If it is not possible to create the algorithm
pyFAI.average.falias of SumAveraging
pyFAI.average.get_monitor_value(image, monitor_key)Return the monitor value from an image using an header key.
Parameters
• image (fabio.fabioimage.FabioImage) – Image containing the header
• monitor_key (str) – Key containing the monitor
Returns returns the monitor else raise an exception
Return type float
Raises MonitorNotFound – when the expected monitor is not found on the header
142 Chapter 6. pyFAI API
![Page 147: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/147.jpg)
pyFAI Documentation, Release 0.15.0a0
pyFAI.average.is_algorithm_name_exists(filter_name)Return true if the name is a name of a filter algorithm
pyFAI.average.remove_saturated_pixel(ds, threshold=0.1, minimum=None, maxi-mum=None)
Remove saturated fixes from an array inplace.
Parameters
• ds – a dataset as ndarray
• threshold (float) – what is the upper limit? all pixel > max*(1-threshold) arediscareded.
• minimum (float) – minumum valid value (or True for auto-guess)
• maximum (float) – maximum valid value
Returns the input dataset
azimuthalIntegrator Module
class pyFAI.azimuthalIntegrator.AzimuthalIntegrator(dist=1, poni1=0, poni2=0,rot1=0, rot2=0, rot3=0,pixel1=None, pixel2=None,splineFile=None, detec-tor=None, wavelength=None)
Bases: pyFAI.geometry.Geometry
This class is an azimuthal integrator based on P. Boesecke’s geometry and histogram algorithm by ManoloS. del Rio and V.A Sole
All geometry calculation are done in the Geometry class
main methods are:
>>> tth, I = ai.integrate1d(data, npt, unit="2th_deg")>>> q, I, sigma = ai.integrate1d(data, npt, unit="q_nm^-1", error_model=→˓"poisson")>>> regrouped = ai.integrate2d(data, npt_rad, npt_azim, unit="q_nm^-1")[0]
DEFAULT_METHOD = ‘splitbbox’
__init__(dist=1, poni1=0, poni2=0, rot1=0, rot2=0, rot3=0, pixel1=None, pixel2=None, spline-File=None, detector=None, wavelength=None)
Parameters
• dist (float) – distance sample - detector plan (orthogonal distance, not along thebeam), in meter.
• poni1 (float) – coordinate of the point of normal incidence along the detector’sfirst dimension, in meter
• poni2 (float) – coordinate of the point of normal incidence along the detector’ssecond dimension, in meter
• rot1 (float) – first rotation from sample ref to detector’s ref, in radians
• rot2 (float) – second rotation from sample ref to detector’s ref, in radians
• rot3 (float) – third rotation from sample ref to detector’s ref, in radians
• pixel1 (float) – Deprecated. Pixel size of the fist dimension of the detector, inmeter. If both pixel1 and pixel2 are not None, detector pixel size is overwritten. Preferdefining the detector pixel size on the provided detector object. Prefer defining thedetector pixel size on the provided detector object (detector.pixel1 = 5e-6).
6.3. azimuthalIntegrator Module 143
![Page 148: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/148.jpg)
pyFAI Documentation, Release 0.15.0a0
• pixel2 (float) – Deprecated. Pixel size of the second dimension of the detector, inmeter. If both pixel1 and pixel2 are not None, detector pixel size is overwritten. Preferdefining the detector pixel size on the provided detector object (detector.pixel2= 5e-6).
• splineFile (str) – Deprecated. File containing the geometric distortion of thedetector. If not None, pixel1 and pixel2 are ignored and detector spline is over-written. Prefer defining the detector spline manually (detector.splineFile= "file.spline").
• detector (str or pyFAI.Detector) – name of the detector or Detector in-stance. String description is deprecated. Prefer using the result of the detector factory:pyFAI.detector_factory("eiger4m")
• wavelength (float) – Wave length used in meter
create_mask(data, mask=None, dummy=None, delta_dummy=None, mode=’normal’)Combines various masks into another one.
Parameters
• data (ndarray) – input array of data
• mask (ndarray) – input mask (if none, self.mask is used)
• dummy (float) – value of dead pixels
• delta_dumy – precision of dummy pixels
• mode (str) – can be “normal” or “numpy” (inverted) or “where” applied to the mask
Returns the new mask
Return type ndarray of bool
This method combine two masks (dynamic mask from data & dummy and mask) to generate a newone with the ‘or’ binary operation. One can adjust the level, with the dummy and the delta_dummyparameter, when you consider the data values needs to be masked out.
This method can work in two different mode:
•“normal”: False for valid pixels, True for bad pixels
•“numpy”: True for valid pixels, false for others
This method tries to accomodate various types of masks (like valid=0 & masked=-1, ...) and guessesif an input mask needs to be inverted.
dark_correction(data, dark=None)Correct for Dark-current effects. If dark is not defined, correct for a dark set by “set_darkfiles”
Parameters
• data – input ndarray with the image
• dark – ndarray with dark noise or None
Returns 2tuple: corrected_data, dark_actually used (or None)
darkcurrent
darkfiles
empty
flat_correction(data, flat=None)Correct for flat field. If flat is not defined, correct for a flat set by “set_flatfiles”
Parameters
• data – input ndarray with the image
• flat – ndarray with flatfield or None for no correction
144 Chapter 6. pyFAI API
![Page 149: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/149.jpg)
pyFAI Documentation, Release 0.15.0a0
Returns 2tuple: corrected_data, flat_actually used (or None)
flatfield
flatfiles
get_darkcurrent()
get_empty()
get_flatfield()
inpainting(data, mask, npt_rad=1024, npt_azim=512, unit=’r_m’, method=’splitpixel’, poisso-nian=False, grow_mask=3)
Re-invent the values of masked pixels
Parameters
• data – input image as 2d numpy array
• mask – masked out pixels array
• npt_rad – number of radial points
• npt_azim – number of azimuthal points
• unit – unit to be used for integration
• method – pathway for integration
• poissonian – If True, add some poisonian noise to the data to make then morerealistic
• grow_mask – grow mask in polar coordinated to accomodate pixel splitting algoritm
Returns inpainting object which contains the restored image as .data
integrate1d(data, npt, filename=None, correctSolidAngle=True, variance=None, er-ror_model=None, radial_range=None, azimuth_range=None, mask=None,dummy=None, delta_dummy=None, polarization_factor=None, dark=None,flat=None, method=’csr’, unit=q_nm^-1, safe=True, normalization_factor=1.0,block_size=32, profile=False, all=False, metadata=None)
Calculate the azimuthal integrated Saxs curve in q(nm^-1) by default
Multi algorithm implementation (tries to be bullet proof), suitable for SAXS, WAXS, ... and muchmore
Parameters
• data (ndarray) – 2D array from the Detector/CCD camera
• npt (int) – number of points in the output pattern
• filename (str) – output filename in 2/3 column ascii format
• correctSolidAngle (bool) – correct for solid angle of each pixel if True
• variance (ndarray) – array containing the variance of the data. If not available,no error propagation is done
• error_model (str) – When the variance is unknown, an error model can be given:“poisson” (variance = I), “azimuthal” (variance = (I-<I>)^2)
• radial_range ((float, float), optional) – The lower and upper rangeof the radial unit. If not provided, range is simply (data.min(), data.max()). Valuesoutside the range are ignored.
• azimuth_range ((float, float), optional) – The lower and upperrange of the azimuthal angle in degree. If not provided, range is simply (data.min(),data.max()). Values outside the range are ignored.
6.3. azimuthalIntegrator Module 145
![Page 150: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/150.jpg)
pyFAI Documentation, Release 0.15.0a0
• mask (ndarray) – array (same size as image) with 1 for masked pixels, and 0 forvalid pixels
• dummy (float) – value for dead/masked pixels
• delta_dummy (float) – precision for dummy value
• polarization_factor (float) – polarization factor between -1 (vertical) and+1 (horizontal). 0 for circular polarization or random, None for no correction, Truefor using the former correction
• dark (ndarray) – dark noise image
• flat (ndarray) – flat field image
• method (str) – can be “numpy”, “cython”, “BBox” or “splitpixel”, “lut”, “csr”,“nosplit_csr”, “full_csr”, “lut_ocl” and “csr_ocl” if you want to go on GPU. To Spec-ify the device: “csr_ocl_1,2”
• unit (pyFAI.units.Unit) – Output units, can be “q_nm^-1”, “q_A^-1”,“2th_deg”, “2th_rad”, “r_mm” for now
• safe (bool) – Do some extra checks to ensure LUT/CSR is still valid. False isfaster.
• normalization_factor (float) – Value of a normalization monitor
• block_size – size of the block for OpenCL integration (unused?)
• profile – set to True to enable profiling in OpenCL
• all (bool) – if true return a dictionary with many more parameters (deprecated,please refer to the documentation of Integrate1dResult).
• metadata – JSON serializable object containing the metadata, usually a dictionary.
Returns q/2th/r bins center positions and regrouped intensity (and error array if variance orvariance model provided), uneless all==True.
Return type Integrate1dResult, dict
integrate2d(data, npt_rad, npt_azim=360, filename=None, correctSolidAngle=True, vari-ance=None, error_model=None, radial_range=None, azimuth_range=None,mask=None, dummy=None, delta_dummy=None, polarization_factor=None,dark=None, flat=None, method=’bbox’, unit=q_nm^-1, safe=True, normaliza-tion_factor=1.0, all=False, metadata=None)
Calculate the azimuthal regrouped 2d image in q(nm^-1)/chi(deg) by default
Multi algorithm implementation (tries to be bullet proof)
Parameters
• data (ndarray) – 2D array from the Detector/CCD camera
• npt_rad (int) – number of points in the radial direction
• npt_azim (int) – number of points in the azimuthal direction
• filename (str) – output image (as edf format)
• correctSolidAngle (bool) – correct for solid angle of each pixel if True
• variance (ndarray) – array containing the variance of the data. If not available,no error propagation is done
• error_model (str) – When the variance is unknown, an error model can be given:“poisson” (variance = I), “azimuthal” (variance = (I-<I>)^2)
• radial_range ((float, float), optional) – The lower and upper rangeof the radial unit. If not provided, range is simply (data.min(), data.max()). Valuesoutside the range are ignored.
146 Chapter 6. pyFAI API
![Page 151: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/151.jpg)
pyFAI Documentation, Release 0.15.0a0
• azimuth_range ((float, float), optional) – The lower and upperrange of the azimuthal angle in degree. If not provided, range is simply (data.min(),data.max()). Values outside the range are ignored.
• mask (ndarray) – array (same size as image) with 1 for masked pixels, and 0 forvalid pixels
• dummy (float) – value for dead/masked pixels
• delta_dummy (float) – precision for dummy value
• polarization_factor (float) – polarization factor between -1 (vertical) and+1 (horizontal). 0 for circular polarization or random, None for no correction
• dark (ndarray) – dark noise image
• flat (ndarray) – flat field image
• method (str) – can be “numpy”, “cython”, “BBox” or “splitpixel”, “lut”,“csr; “lut_ocl” and “csr_ocl” if you want to go on GPU. To Specify the device:“csr_ocl_1,2”
• unit (pyFAI.units.Unit) – Output units, can be “q_nm^-1”, “q_A^-1”,“2th_deg”, “2th_rad”, “r_mm” for now
• safe (bool) – Do some extra checks to ensure LUT is still valid. False is faster.
• normalization_factor (float) – Value of a normalization monitor
• all (bool) – if true, return many more intermediate results as a dict (deprecated,please refer to the documentation of Integrate2dResult).
• metadata – JSON serializable object containing the metadata, usually a dictionary.
Returns azimuthaly regrouped intensity, q/2theta/r pos. and chi pos.
Return type Integrate2dResult, dict
integrate_radial(data, npt, npt_rad=100, correctSolidAngle=True, radial_range=None, az-imuth_range=None, mask=None, dummy=None, delta_dummy=None,polarization_factor=None, dark=None, flat=None, method=’csr’,unit=chi_deg, radial_unit=q_nm^-1, normalization_factor=1.0)
Calculate the radial integrated profile curve as I = f(chi)
Parameters
• data (ndarray) – 2D array from the Detector/CCD camera
• npt (int) – number of points in the output pattern
• npt_rad (int) – number of points in the radial space. Too few points may lead tohuge rounding errors.
• filename (str) – output filename in 2/3 column ascii format
• correctSolidAngle (bool) – correct for solid angle of each pixel if True
• radial_range (Tuple(float, float)) – The lower and upper range of theradial unit. If not provided, range is simply (data.min(), data.max()). Values outsidethe range are ignored. Optional.
• azimuth_range (Tuple(float, float)) – The lower and upper range of theazimuthal angle in degree. If not provided, range is simply (data.min(), data.max()).Values outside the range are ignored. Optional.
• mask (ndarray) – array (same size as image) with 1 for masked pixels, and 0 forvalid pixels
• dummy (float) – value for dead/masked pixels
• delta_dummy (float) – precision for dummy value
6.3. azimuthalIntegrator Module 147
![Page 152: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/152.jpg)
pyFAI Documentation, Release 0.15.0a0
• polarization_factor (float) – polarization factor between -1 (vertical) and+1 (horizontal). * 0 for circular polarization or random, * None for no correction, *True for using the former correction
• dark (ndarray) – dark noise image
• flat (ndarray) – flat field image
• method (str) – can be “numpy”, “cython”, “BBox” or “splitpixel”, “lut”, “csr”,“nosplit_csr”, “full_csr”, “lut_ocl” and “csr_ocl” if you want to go on GPU. To Spec-ify the device: “csr_ocl_1,2”
• unit (pyFAI.units.Unit) – Output units, can be “chi_deg” or “chi_rad”
• radial_unit (pyFAI.units.Unit) – unit used for radial representation, canbe “q_nm^-1”, “q_A^-1”, “2th_deg”, “2th_rad”, “r_mm” for now
• normalization_factor (float) – Value of a normalization monitor
Returns chi bins center positions and regrouped intensity
Return type Integrate1dResult
medfilt1d(data, npt_rad=1024, npt_azim=512, correctSolidAngle=True, polariza-tion_factor=None, dark=None, flat=None, method=’splitpixel’, unit=q_nm^-1,percentile=50, mask=None, normalization_factor=1.0, metadata=None)
Perform the 2D integration and filter along each row using a median filter
Parameters
• data – input image as numpy array
• npt_rad – number of radial points
• npt_azim – number of azimuthal points
• correctSolidAngle (bool) – correct for solid angle of each pixel if True
• polarization_factor (float) – polarization factor between -1 (vertical) and+1 (horizontal). 0 for circular polarization or random, None for no correction, Truefor using the former correction
• dark (ndarray) – dark noise image
• flat (ndarray) – flat field image
• unit – unit to be used for integration
• method – pathway for integration and sort
• percentile – which percentile use for cutting out percentil can be a 2-tuple tospecify a region to average out
• mask – masked out pixels array
• normalization_factor (float) – Value of a normalization monitor
• metadata (JSON serializable dict) – any other metadata,
Returns Integrate1D like result like
reset()Reset azimuthal integrator in addition to other arrays.
save1D(*arg, **kw)decorator that deprecates the use of a function
save2D(*arg, **kw)decorator that deprecates the use of a function
saxs(*arg, **kw)decorator that deprecates the use of a function
148 Chapter 6. pyFAI API
![Page 153: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/153.jpg)
pyFAI Documentation, Release 0.15.0a0
separate(data, npt_rad=1024, npt_azim=512, unit=‘2th_deg’, method=’splitpixel’, per-centile=50, mask=None, restore_mask=True)
Separate bragg signal from powder/amorphous signal using azimuthal integration, median filering andprojected back before subtraction.
Parameters
• data – input image as numpy array
• npt_rad – number of radial points
• npt_azim – number of azimuthal points
• unit – unit to be used for integration
• method – pathway for integration and sort
• percentile – which percentile use for cutting out
• mask – masked out pixels array
• restore_mask – masked pixels have the same value as input data provided
Returns bragg, amorphous
set_darkcurrent(dark)
set_darkfiles(files=None, method=’mean’)Moved to Detector
Parameters
• files (str or list(str) or None) – file(s) used to compute the dark.
• method (str) – method used to compute the dark, “mean” or “median”
Set the dark current from one or mutliple files, avaraged according to the method provided
set_empty(value)
set_flatfield(flat)
set_flatfiles(files, method=’mean’)Moved to Detector
Parameters
• files (str or list(str) or None) – file(s) used to compute the flat-field.
• method (str) – method used to compute the dark, “mean” or “median”
Set the flat field from one or mutliple files, averaged according to the method provided
setup_CSR(shape, npt, mask=None, pos0_range=None, pos1_range=None,mask_checksum=None, unit=2th_deg, split=’bbox’)
Prepare a look-up-table
Parameters
• shape ((int, int)) – shape of the dataset
• npt (int or (int, int)) – number of points in the the output pattern
• mask (ndarray) – array with masked pixel (1=masked)
• pos0_range ((float, float)) – range in radial dimension
• pos1_range ((float, float)) – range in azimuthal dimension
• mask_checksum (int (or anything else ...)) – checksum of the maskbuffer
• unit (pyFAI.units.Unit) – use to propagate the LUT object for further check-ings
6.3. azimuthalIntegrator Module 149
![Page 154: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/154.jpg)
pyFAI Documentation, Release 0.15.0a0
• split – Splitting scheme: valid options are “no”, “bbox”, “full”
This method is called when a look-up table needs to be set-up. The shape parameter, correspond to theshape of the original datatset. It is possible to customize the number of point of the output histogramwith the npt parameter which can be either an integer for an 1D integration or a 2-tuple of integer incase of a 2D integration. The LUT will have a different shape: (npt, lut_max_size), the later parameterbeing calculated during the instanciation of the splitBBoxLUT class.
It is possible to prepare the LUT with a predefine mask. This operation can speedup the computationof the later integrations. Instead of applying the patch on the dataset, it is taken into account during thehistogram computation. If provided the mask_checksum prevent the re-calculation of the mask. Whenthe mask changes, its checksum is used to reset (or not) the LUT (which is a very time consumingoperation !)
It is also possible to restrain the range of the 1D or 2D pattern with the pos1_range and pos2_range.
The unit parameter is just propagated to the LUT integrator for further checkings: The aim is to preventan integration to be performed in 2th-space when the LUT was setup in q space.
setup_LUT(shape, npt, mask=None, pos0_range=None, pos1_range=None,mask_checksum=None, unit=2th_deg)
Prepare a look-up-table
Parameters
• shape ((int, int)) – shape of the dataset
• npt (int or (int, int)) – number of points in the the output pattern
• mask (ndarray) – array with masked pixel (1=masked)
• pos0_range ((float, float)) – range in radial dimension
• pos1_range ((float, float)) – range in azimuthal dimension
• mask_checksum (int (or anything else ...)) – checksum of the maskbuffer
• unit (pyFAI.units.Unit) – use to propagate the LUT object for further check-ings
This method is called when a look-up table needs to be set-up. The shape parameter, correspond to theshape of the original datatset. It is possible to customize the number of point of the output histogramwith the npt parameter which can be either an integer for an 1D integration or a 2-tuple of integer incase of a 2D integration. The LUT will have a different shape: (npt, lut_max_size), the later parameterbeing calculated during the instanciation of the splitBBoxLUT class.
It is possible to prepare the LUT with a predefine mask. This operation can speedup the computationof the later integrations. Instead of applying the patch on the dataset, it is taken into account during thehistogram computation. If provided the mask_checksum prevent the re-calculation of the mask. Whenthe mask changes, its checksum is used to reset (or not) the LUT (which is a very time consumingoperation !)
It is also possible to restrain the range of the 1D or 2D pattern with the pos1_range and pos2_range.
The unit parameter is just propagated to the LUT integrator for further checkings: The aim is to preventan integration to be performed in 2th-space when the LUT was setup in q space.
sigma_clip(data, npt_rad=1024, npt_azim=512, correctSolidAngle=True, polariza-tion_factor=None, dark=None, flat=None, method=’splitpixel’, unit=q_nm^-1,thres=3, max_iter=5, mask=None, normalization_factor=1.0, metadata=None)
Perform the 2D integration and perform a sigm-clipping iterative filter along each row. see the doc ofscipy.stats.sigmaclip for the options.
Parameters
• data – input image as numpy array
• npt_rad – number of radial points
150 Chapter 6. pyFAI API
![Page 155: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/155.jpg)
pyFAI Documentation, Release 0.15.0a0
• npt_azim – number of azimuthal points
• correctSolidAngle (bool) – correct for solid angle of each pixel if True
• polarization_factor (float) – polarization factor between -1 (vertical) and+1 (horizontal). 0 for circular polarization or random, None for no correction, Truefor using the former correction
• dark (ndarray) – dark noise image
• flat (ndarray) – flat field image
• unit – unit to be used for integration
• method – pathway for integration and sort
• thres – cut-off for n*sigma: discard any values with (I-<I>)/sigma > thres. Thethreshold can be a 2-tuple with sigma_low and sigma_high.
• max_iter – maximum number of iterations :param mask: masked out pixels array
• normalization_factor (float) – Value of a normalization monitor
• metadata (JSON serializable dict) – any other metadata,
Returns Integrate1D like result like
xrpd(*arg, **kw)decorator that deprecates the use of a function
xrpd2(*arg, **kw)decorator that deprecates the use of a function
xrpd2_histogram(*arg, **kw)decorator that deprecates the use of a function
xrpd2_numpy(*arg, **kw)decorator that deprecates the use of a function
xrpd2_splitBBox(*arg, **kw)decorator that deprecates the use of a function
xrpd2_splitPixel(*arg, **kw)decorator that deprecates the use of a function
xrpd_CSR_OCL(*arg, **kw)decorator that deprecates the use of a function
xrpd_LUT(*arg, **kw)decorator that deprecates the use of a function
xrpd_LUT_OCL(*arg, **kw)decorator that deprecates the use of a function
xrpd_OpenCL(*arg, **kw)decorator that deprecates the use of a function
xrpd_cython(*arg, **kw)decorator that deprecates the use of a function
xrpd_numpy(*arg, **kw)decorator that deprecates the use of a function
xrpd_splitBBox(*arg, **kw)decorator that deprecates the use of a function
xrpd_splitPixel(*arg, **kw)decorator that deprecates the use of a function
6.3. azimuthalIntegrator Module 151
![Page 156: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/156.jpg)
pyFAI Documentation, Release 0.15.0a0
multi_geometry Module
Module for treating simultaneously multiple detector configuration within a single integration
class pyFAI.multi_geometry.MultiGeometry(ais, unit=‘2th_deg’, radial_range=(0, 180),azimuth_range=(-180, 180), wavelength=None,empty=0.0, chi_disc=180)
Bases: object
This is an Azimuthal integrator containing multiple geometries, for example when the detector is on agoniometer arm
__init__(ais, unit=‘2th_deg’, radial_range=(0, 180), azimuth_range=(-180, 180), wave-length=None, empty=0.0, chi_disc=180)
Constructor of the multi-geometry integrator :param ais: list of azimuthal integrators :param ra-dial_range: common range for integration :param azimuthal_range: common range for integration:param empty: value for empty pixels :param chi_disc: if 0, set the chi_discontinuity at
integrate1d(lst_data, npt=1800, correctSolidAngle=True, lst_variance=None, er-ror_model=None, polarization_factor=None, normalization_factor=None,all=False, lst_mask=None, lst_flat=None)
Perform 1D azimuthal integration
Parameters
• lst_data – list of numpy array
• npt – number of points int the integration
• correctSolidAngle – correct for solid angle (all processing are then done inabsolute solid angle !)
• lst_variance (list of ndarray) – list of array containing the variance ofthe data. If not available, no error propagation is done
• error_model (str) – When the variance is unknown, an error model can be given:“poisson” (variance = I), “azimuthal” (variance = (I-<I>)^2)
• polarization_factor – Apply polarization correction ? is None: not applies.Else provide a value from -1 to +1
• normalization_factor – normalization monitors value (list of floats)
• all – return a dict with all information in it (deprecated, please refer to the documen-tation of Integrate1dResult).
• lst_mask – numpy.Array or list of numpy.array which mask the lst_data.
• lst_flat – numpy.Array or list of numpy.array which flat the lst_data.
Returns 2th/I or a dict with everything depending on “all”
Return type Integrate1dResult, dict
integrate2d(lst_data, npt_rad=1800, npt_azim=3600, correctSolidAngle=True,lst_variance=None, error_model=None, polarization_factor=None, normal-ization_factor=None, all=False, lst_mask=None, lst_flat=None)
Performs 2D azimuthal integration of multiples frames, one for each geometry
Parameters
• lst_data – list of numpy array
• npt – number of points int the integration
• correctSolidAngle – correct for solid angle (all processing are then done inabsolute solid angle !)
• lst_variance (list of ndarray) – list of array containing the variance ofthe data. If not available, no error propagation is done
152 Chapter 6. pyFAI API
![Page 157: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/157.jpg)
pyFAI Documentation, Release 0.15.0a0
• error_model (str) – When the variance is unknown, an error model can be given:“poisson” (variance = I), “azimuthal” (variance = (I-<I>)^2)
• polarization_factor – Apply polarization correction ? is None: not applies.Else provide a value from -1 to +1
• normalization_factor – normalization monitors value (list of floats)
• all – return a dict with all information in it (deprecated, please refer to the documen-tation of Integrate2dResult).
• lst_mask – numpy.Array or list of numpy.array which mask the lst_data.
• lst_flat – numpy.Array or list of numpy.array which flat the lst_data.
Returns I/2th/chi or a dict with everything depending on “all”
Return type Integrate2dResult, dict
set_wavelength(value)Changes the wavelength of a group of azimuthal integrators
integrate_widget Module
geometry Module
This modules contains only one (large) class in charge of:
• calculating the geometry, i.e. the position in the detector space of each pixel of the detector
• manages caches to store intermediate results
class pyFAI.geometry.Geometry(dist=1, poni1=0, poni2=0, rot1=0, rot2=0, rot3=0, pixel1=None,pixel2=None, splineFile=None, detector=None, wave-length=None)
Bases: object
This class is an azimuthal integrator based on P. Boesecke’s geometry and histogram algorithm by ManoloS. del Rio and V.A Sole
Detector is assumed to be corrected from “raster orientation” effect. It is not addressed here but rather inthe Detector object or at read time. Considering there is no tilt:
•Detector fast dimension (dim2) is supposed to be horizontal (dimension X of the image)
•Detector slow dimension (dim1) is supposed to be vertical, upwards (dimension Y of the image)
•The third dimension is chose such as the referential is orthonormal, so dim3 is along incoming X-raybeam
Demonstration of the equation done using Mathematica:
Axis 1 is allong first dimension of detector (when not tilted), this is the→˓slow dimension of the image array in C or YIn[5]:= x1={1,0,0}Out[5]= {1,0,0}Axis 2 is allong second dimension of detector (when not tilted), this is the→˓fast dimension of the image in C or XIn[6]:= x2={0,1,0}Out[6]= {0,1,0}Axis 3 is along the incident X-Ray beamIn[7]:= x3={0,0,1}Out[7]= {0,0,1}In[9]:= id3={x1,x2,x3}Out[9]= {{1,0,0},{0,1,0},{0,0,1}}
6.5. integrate_widget Module 153
![Page 158: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/158.jpg)
pyFAI Documentation, Release 0.15.0a0
In[10]:= {{1,0,0},{0,1,0},{0,0,1}}Out[10]= {{1,0,0},{0,1,0},{0,0,1}}In[11]:= rotM1=RotationMatrix[rot1,x1]Out[11]= {{1,0,0},{0,Cos[rot1],-Sin[rot1]},{0,Sin[rot1],Cos[rot1]}}In[12]:= rotM2 = RotationMatrix[rot2,x2]Out[12]= {{Cos[rot2],0,Sin[rot2]},{0,1,0},{-Sin[rot2],0,Cos[rot2]}}In[13]:= rotM3 = RotationMatrix[rot3,x3]Out[13]= {{Cos[rot3],-Sin[rot3],0},{Sin[rot3],Cos[rot3],0},{0,0,1}}Rotations of the detector are applied first Rot around axis 1, then axis 2 and→˓finally around axis 3In[14]:= R=rotM3.rotM2.rotM1Out[14]= {{Cos[rot2] Cos[rot3],Cos[rot3] Sin[rot1] Sin[rot2]-Cos[rot1]→˓Sin[rot3],Cos[rot1] Cos[rot3] Sin[rot2]+Sin[rot1] Sin[rot3]},{Cos[rot2]→˓Sin[rot3],Cos[rot1] Cos[rot3]+Sin[rot1] Sin[rot2] Sin[rot3],-Cos[rot3]→˓Sin[rot1]+Cos[rot1] Sin[rot2] Sin[rot3]},{-Sin[rot2],Cos[rot2] Sin[rot1],→˓Cos[rot1] Cos[rot2]}}In[15]:= CForm[R.x1]
Out[15]//CForm=List(Cos(rot2)*Cos(rot3),Cos(rot2)*Sin(rot3),-Sin(rot2))In[16]:= CForm[R.x2]
Out[16]//CForm=List(Cos(rot3)*Sin(rot1)*Sin(rot2) - Cos(rot1)*Sin(rot3),Cos(rot1)*Cos(rot3) +→˓Sin(rot1)*Sin(rot2)*Sin(rot3),Cos(rot2)*Sin(rot1))In[17]:= CForm[R.x3]Out[17]//CForm=List(Cos(rot1)*Cos(rot3)*Sin(rot2) + Sin(rot1)*Sin(rot3),-→˓(Cos(rot3)*Sin(rot1)) + Cos(rot1)*Sin(rot2)*Sin(rot3),Cos(rot1)*Cos(rot2))In[18]:= CForm[Det[R]]Out[18]//CForm=Power(Cos(rot1),2)*Power(Cos(rot2),2)*Power(Cos(rot3),2) + Power(Cos(rot2),→˓2)*Power(Cos(rot3),2)*Power(Sin(rot1),2) + Power(Cos(rot1),→˓2)*Power(Cos(rot3),2)*Power(Sin(rot2),2) +
Power(Cos(rot3),2)*Power(Sin(rot1),2)*Power(Sin(rot2),2) + Power(Cos(rot1),→˓2)*Power(Cos(rot2),2)*Power(Sin(rot3),2) + Power(Cos(rot2),→˓2)*Power(Sin(rot1),2)*Power(Sin(rot3),2) +
Power(Cos(rot1),2)*Power(Sin(rot2),2)*Power(Sin(rot3),2) + Power(Sin(rot1),→˓2)*Power(Sin(rot2),2)*Power(Sin(rot3),2)In[13]:=Any pixel on detector plan at coordianate (d1, d2) in meters. Detector is at→˓z=L
In[22]:= P={d1,d2,L}CForm[R.P]
Out[22]= {d1,d2,L}Out[23]//CForm=List(d1*Cos(rot2)*Cos(rot3) + d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) -→˓Cos(rot1)*Sin(rot3)) + L*(Cos(rot1)*Cos(rot3)*Sin(rot2) +→˓Sin(rot1)*Sin(rot3)),
d1*Cos(rot2)*Sin(rot3) + L*(-(Cos(rot3)*Sin(rot1)) +→˓Cos(rot1)*Sin(rot2)*Sin(rot3)) + d2*(Cos(rot1)*Cos(rot3) +→˓Sin(rot1)*Sin(rot2)*Sin(rot3)),L*Cos(rot1)*Cos(rot2) +→˓d2*Cos(rot2)*Sin(rot1) - d1*Sin(rot2))In[24]:= t1 = R.P.x1CForm[t1]Out[24]= d1 Cos[rot2] Cos[rot3]+d2 (Cos[rot3] Sin[rot1] Sin[rot2]-Cos[rot1]→˓Sin[rot3])+L (Cos[rot1] Cos[rot3] Sin[rot2]+Sin[rot1] Sin[rot3])Out[25]//CForm=d1*Cos(rot2)*Cos(rot3) + d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) -→˓Cos(rot1)*Sin(rot3)) + L*(Cos(rot1)*Cos(rot3)*Sin(rot2) +→˓Sin(rot1)*Sin(rot3))
154 Chapter 6. pyFAI API
![Page 159: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/159.jpg)
pyFAI Documentation, Release 0.15.0a0
In[26]:= t2 = R.P.x2CForm[t2]Out[26]= d1 Cos[rot2] Sin[rot3]+L (-Cos[rot3] Sin[rot1]+Cos[rot1] Sin[rot2]→˓Sin[rot3])+d2 (Cos[rot1] Cos[rot3]+Sin[rot1] Sin[rot2] Sin[rot3])Out[27]//CForm=d1*Cos(rot2)*Sin(rot3) + L*(-(Cos(rot3)*Sin(rot1)) +→˓Cos(rot1)*Sin(rot2)*Sin(rot3)) + d2*(Cos(rot1)*Cos(rot3) +→˓Sin(rot1)*Sin(rot2)*Sin(rot3))In[28]:= t3=R.P.x3CForm[t3]Out[28]= L Cos[rot1] Cos[rot2]+d2 Cos[rot2] Sin[rot1]-d1 Sin[rot2]Out[29]//CForm=L*Cos(rot1)*Cos(rot2) + d2*Cos(rot2)*Sin(rot1) - d1*Sin(rot2)Distance sample to detector point (d1,d2)(no Mathematica translations)GraphicsBox[TagBox[RasterBox[CompressedData["1:eJxtUstqU1EUDY2iUdSOnBcERwGHDgQf+YNGOrAQSEBBBwlWQfsDcVKsI4sfIAQnGSQtCQ4yyfvVvO69SW7J+9W8GtIkg8SwXfuQSpFu2Pdxzl5rr7XP2bDYNt+saTSaDzfx2DR/er6zY941XsPPi92Pry1afNxdJS9ejuFwqJNl+XMsFstEo1HijEQio1Qq9bPZbD7SXBHtdnsjGAxK+Xyeut0uTadTms1mNBgMqFwuUyKR+APOd5cxo9HoHjBqqVSis7Mzms/nlMlkyOfziX/GdzodSiaTpCjKqwscar6oqkq9Xo/Oz89pb2+PjEYj2Ww22t7epn6/L/DcF/wdt9u9Di4tPAxarZbgZKzdbmde4jCZTORyuUTPWq1G8Erwb0HdQ2gn+KZ6vU6np6eCm8PhcNDW1hZVKhWxxvusH/P6jronwVCIcpJE2VxOvLvQ5Q8EyGAwkMfjERilUBCYCGrj8fiv8Xj8IIAa1iVJMsnIIWZ4dHRE+1/3hW72pUgK5cALTzyfbzwX4Kt5WSb15IRU8M5wBgcHB2S1WqkL3TxntVgU3CH0g7+XjGs0Gm/D4bDgZS/QQH6/n5xOp+iH/X8zQY+0Xq9fZ9xyudRKknTIGpibZzOZTMQMcYeoWq1SNptlzMzr9T4G5PbFGS4WC12hUHDwbNlHEbr4TMEn7hvW69DwDKV3kGv/3zfUPU2n0z+g6Rj+j/H+jXxvNpvvr/por7qnq+C9G8hbq9Qhr18u+AttYAMa"], {{0, 14}, {14, 0}}, {0, 255},ColorFunction->RGBColor],BoxForm`ImageTag["Byte", ColorSpace -> "RGB", Interleaving -> True],Selectable->False],BaseStyle->"ImageGraphics",ImageSize->Magnification[1],ImageSizeRaw->{14, 14},PlotRange->{{0, 14}, {0, 14}}]
In[30]:= dist = Norm[R.P]CForm[dist]Out[30]= (Abs[L Cos[rot1] Cos[rot2]+d2 Cos[rot2] Sin[rot1]-d1 Sin[rot2]]^→˓2+Abs[d1 Cos[rot2] Cos[rot3]+d2 (Cos[rot3] Sin[rot1] Sin[rot2]-Cos[rot1]→˓Sin[rot3])+L (Cos[rot1] Cos[rot3] Sin[rot2]+Sin[rot1] Sin[rot3])]^2+Abs[d1→˓Cos[rot2] Sin[rot3]+L (-Cos[rot3] Sin[rot1]+Cos[rot1] Sin[rot2]→˓Sin[rot3])+d2 (Cos[rot1] Cos[rot3]+Sin[rot1] Sin[rot2] Sin[rot3])]^2)Out[31]//CForm=Sqrt(Power(Abs(L*Cos(rot1)*Cos(rot2) + d2*Cos(rot2)*Sin(rot1) - d1*Sin(rot2)),→˓2) + Power(Abs(d1*Cos(rot2)*Cos(rot3) + d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) -→˓Cos(rot1)*Sin(rot3)) +
L*(Cos(rot1)*Cos(rot3)*Sin(rot2) + Sin(rot1)*Sin(rot3))),2) +→˓Power(Abs(d1*Cos(rot2)*Sin(rot3) + L*(-(Cos(rot3)*Sin(rot1)) +→˓Cos(rot1)*Sin(rot2)*Sin(rot3)) + d2*(Cos(rot1)*Cos(rot3) +→˓Sin(rot1)*Sin(rot2)*Sin(rot3))),
2))cos(2theta) can be defined as (R.P component along x3) over the distance |R.P|In[32]:= tthc = ArcCos [-(R.P).x3/Norm[R.P]]CForm[tthc]
Out[32]= ArcCos[(-L Cos[rot1] Cos[rot2]-d2 Cos[rot2] Sin[rot1]+d1 Sin[rot2])/→˓((Abs[L Cos[rot1] Cos[rot2]+d2 Cos[rot2] Sin[rot1]-d1 Sin[rot2]]^2+Abs[d1→˓Cos[rot2] Cos[rot3]+d2 (Cos[rot3] Sin[rot1] Sin[rot2]-Cos[rot1] Sin[rot3])+L→˓(Cos[rot1] Cos[rot3] Sin[rot2]+Sin[rot1] Sin[rot3])]^2+Abs[d1 Cos[rot2]→˓Sin[rot3]+L (-Cos[rot3] Sin[rot1]+Cos[rot1] Sin[rot2] Sin[rot3])+d2→˓(Cos[rot1] Cos[rot3]+Sin[rot1] Sin[rot2] Sin[rot3])]^2))]6.6. geometry Module 155
![Page 160: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/160.jpg)
pyFAI Documentation, Release 0.15.0a0
Out[33]//CForm=ArcCos((-(L*Cos(rot1)*Cos(rot2)) - d2*Cos(rot2)*Sin(rot1) + d1*Sin(rot2))/
Sqrt(Power(Abs(L*Cos(rot1)*Cos(rot2) + d2*Cos(rot2)*Sin(rot1) -→˓d1*Sin(rot2)),2) + Power(Abs(d1*Cos(rot2)*Cos(rot3) +→˓d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) - Cos(rot1)*Sin(rot3)) +
L*(Cos(rot1)*Cos(rot3)*Sin(rot2) + Sin(rot1)*Sin(rot3))),2) +→˓Power(Abs(d1*Cos(rot2)*Sin(rot3) + L*(-(Cos(rot3)*Sin(rot1)) +→˓Cos(rot1)*Sin(rot2)*Sin(rot3)) +
d2*(Cos(rot1)*Cos(rot3) + Sin(rot1)*Sin(rot2)*Sin(rot3))),2)))
In[41]:= ttht = ArcTan[t3,Sqrt[t1^2 + t2^2]]
CForm[ttht]
Out[41]= ArcTan[L Cos[rot1] Cos[rot2]+d2 Cos[rot2] Sin[rot1]-d1 Sin[rot2],((d1→˓Cos[rot2] Cos[rot3]+d2 (Cos[rot3] Sin[rot1] Sin[rot2]-Cos[rot1] Sin[rot3])+L→˓(Cos[rot1] Cos[rot3] Sin[rot2]+Sin[rot1] Sin[rot3]))^2+(d1 Cos[rot2]→˓Sin[rot3]+L (-Cos[rot3] Sin[rot1]+Cos[rot1] Sin[rot2] Sin[rot3])+d2→˓(Cos[rot1] Cos[rot3]+Sin[rot1] Sin[rot2] Sin[rot3]))^2)]Out[42]//CForm=ArcTan(L*Cos(rot1)*Cos(rot2) + d2*Cos(rot2)*Sin(rot1) - d1*Sin(rot2),→˓Sqrt(Power(d1*Cos(rot2)*Cos(rot3) + d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) -→˓Cos(rot1)*Sin(rot3)) + L*(Cos(rot1)*Cos(rot3)*Sin(rot2) +→˓Sin(rot1)*Sin(rot3)),
2) + Power(d1*Cos(rot2)*Sin(rot3) + L*(-(Cos(rot3)*Sin(rot1)) +→˓Cos(rot1)*Sin(rot2)*Sin(rot3)) + d2*(Cos(rot1)*Cos(rot3) +→˓Sin(rot1)*Sin(rot2)*Sin(rot3)),2)))Tangeant of angle chi is defined as (R.P component along x1) over (R.P→˓component along x2). Arctan2 should be used in actual calculationIn[36]:= chi =ArcTan[t1 , t2]CForm[chi]Out[36]= ArcTan[d1 Cos[rot2] Cos[rot3]+d2 (Cos[rot3] Sin[rot1] Sin[rot2]-→˓Cos[rot1] Sin[rot3])+L (Cos[rot1] Cos[rot3] Sin[rot2]+Sin[rot1] Sin[rot3]),→˓d1 Cos[rot2] Sin[rot3]+L (-Cos[rot3] Sin[rot1]+Cos[rot1] Sin[rot2]→˓Sin[rot3])+d2 (Cos[rot1] Cos[rot3]+Sin[rot1] Sin[rot2] Sin[rot3])]Out[37]//CForm=ArcTan(d1*Cos(rot2)*Cos(rot3) + d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) -→˓Cos(rot1)*Sin(rot3)) + L*(Cos(rot1)*Cos(rot3)*Sin(rot2) +→˓Sin(rot1)*Sin(rot3)),
d1*Cos(rot2)*Sin(rot3) + L*(-(Cos(rot3)*Sin(rot1)) +→˓Cos(rot1)*Sin(rot2)*Sin(rot3)) + d2*(Cos(rot1)*Cos(rot3) +→˓Sin(rot1)*Sin(rot2)*Sin(rot3)))Coodinates of the Point of Normal Incidence
In[38]:= PONI = R.{0,0,L}CForm[PONI]Out[38]= {L (Cos[rot1] Cos[rot3] Sin[rot2]+Sin[rot1] Sin[rot3]),L (-Cos[rot3]→˓Sin[rot1]+Cos[rot1] Sin[rot2] Sin[rot3]),L Cos[rot1] Cos[rot2]}Out[39]//CForm=List(L*(Cos(rot1)*Cos(rot3)*Sin(rot2) + Sin(rot1)*Sin(rot3)),L*(-→˓(Cos(rot3)*Sin(rot1)) + Cos(rot1)*Sin(rot2)*Sin(rot3)),L*Cos(rot1)*Cos(rot2))Derivatives of 2ThetaIn[43]:= CForm[D[ttht,d1]]Out[43]//CForm=((L*Cos(rot1)*Cos(rot2) + d2*Cos(rot2)*Sin(rot1) -→˓d1*Sin(rot2))*(2*Cos(rot2)*Cos(rot3)*(d1*Cos(rot2)*Cos(rot3) +→˓d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) - Cos(rot1)*Sin(rot3)) +
L*(Cos(rot1)*Cos(rot3)*Sin(rot2) + Sin(rot1)*Sin(rot3))) +→˓2*Cos(rot2)*Sin(rot3)*
(d1*Cos(rot2)*Sin(rot3) + L*(-(Cos(rot3)*Sin(rot1)) +→˓Cos(rot1)*Sin(rot2)*Sin(rot3)) + d2*(Cos(rot1)*Cos(rot3) +→˓Sin(rot1)*Sin(rot2)*Sin(rot3)))))/
156 Chapter 6. pyFAI API
![Page 161: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/161.jpg)
pyFAI Documentation, Release 0.15.0a0
(2.*Sqrt(Power(d1*Cos(rot2)*Cos(rot3) + d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) -→˓ Cos(rot1)*Sin(rot3)) + L*(Cos(rot1)*Cos(rot3)*Sin(rot2) +→˓Sin(rot1)*Sin(rot3)),2) +
Power(d1*Cos(rot2)*Sin(rot3) + L*(-(Cos(rot3)*Sin(rot1)) +→˓Cos(rot1)*Sin(rot2)*Sin(rot3)) + d2*(Cos(rot1)*Cos(rot3) +→˓Sin(rot1)*Sin(rot2)*Sin(rot3)),2))*
(Power(L*Cos(rot1)*Cos(rot2) + d2*Cos(rot2)*Sin(rot1) - d1*Sin(rot2),2)→˓+ Power(d1*Cos(rot2)*Cos(rot3) + d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) -→˓Cos(rot1)*Sin(rot3)) +
L*(Cos(rot1)*Cos(rot3)*Sin(rot2) + Sin(rot1)*Sin(rot3)),2) +→˓Power(d1*Cos(rot2)*Sin(rot3) + L*(-(Cos(rot3)*Sin(rot1)) +→˓Cos(rot1)*Sin(rot2)*Sin(rot3)) + d2*(Cos(rot1)*Cos(rot3) +→˓Sin(rot1)*Sin(rot2)*Sin(rot3)),2)))
+ (Sin(rot2)*Sqrt(Power(d1*Cos(rot2)*Cos(rot3) +→˓d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) - Cos(rot1)*Sin(rot3)) +→˓L*(Cos(rot1)*Cos(rot3)*Sin(rot2) + Sin(rot1)*Sin(rot3)),2) +
Power(d1*Cos(rot2)*Sin(rot3) + L*(-(Cos(rot3)*Sin(rot1)) +→˓Cos(rot1)*Sin(rot2)*Sin(rot3)) + d2*(Cos(rot1)*Cos(rot3) +→˓Sin(rot1)*Sin(rot2)*Sin(rot3)),2)))/
(Power(L*Cos(rot1)*Cos(rot2) + d2*Cos(rot2)*Sin(rot1) - d1*Sin(rot2),2) +→˓Power(d1*Cos(rot2)*Cos(rot3) + d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) -→˓Cos(rot1)*Sin(rot3)) + L*(Cos(rot1)*Cos(rot3)*Sin(rot2) +→˓Sin(rot1)*Sin(rot3)),
2) + Power(d1*Cos(rot2)*Sin(rot3) + L*(-(Cos(rot3)*Sin(rot1)) +→˓Cos(rot1)*Sin(rot2)*Sin(rot3)) + d2*(Cos(rot1)*Cos(rot3) +→˓Sin(rot1)*Sin(rot2)*Sin(rot3)),2))In[44]:= CForm[D[ttht,d2]]
Out[44]//CForm=((L*Cos(rot1)*Cos(rot2) + d2*Cos(rot2)*Sin(rot1) -→˓d1*Sin(rot2))*(2*(Cos(rot3)*Sin(rot1)*Sin(rot2) - Cos(rot1)*Sin(rot3))*
(d1*Cos(rot2)*Cos(rot3) + d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) -→˓Cos(rot1)*Sin(rot3)) + L*(Cos(rot1)*Cos(rot3)*Sin(rot2) +→˓Sin(rot1)*Sin(rot3))) +
2*(Cos(rot1)*Cos(rot3) +→˓Sin(rot1)*Sin(rot2)*Sin(rot3))*(d1*Cos(rot2)*Sin(rot3) + L*(-→˓(Cos(rot3)*Sin(rot1)) + Cos(rot1)*Sin(rot2)*Sin(rot3)) +→˓d2*(Cos(rot1)*Cos(rot3) + Sin(rot1)*Sin(rot2)*Sin(rot3)))))/
(2.*Sqrt(Power(d1*Cos(rot2)*Cos(rot3) + d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) -→˓ Cos(rot1)*Sin(rot3)) + L*(Cos(rot1)*Cos(rot3)*Sin(rot2) +→˓Sin(rot1)*Sin(rot3)),2) +
Power(d1*Cos(rot2)*Sin(rot3) + L*(-(Cos(rot3)*Sin(rot1)) +→˓Cos(rot1)*Sin(rot2)*Sin(rot3)) + d2*(Cos(rot1)*Cos(rot3) +→˓Sin(rot1)*Sin(rot2)*Sin(rot3)),2))*
(Power(L*Cos(rot1)*Cos(rot2) + d2*Cos(rot2)*Sin(rot1) - d1*Sin(rot2),2)→˓+ Power(d1*Cos(rot2)*Cos(rot3) + d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) -→˓Cos(rot1)*Sin(rot3)) +
L*(Cos(rot1)*Cos(rot3)*Sin(rot2) + Sin(rot1)*Sin(rot3)),2) +→˓Power(d1*Cos(rot2)*Sin(rot3) + L*(-(Cos(rot3)*Sin(rot1)) +→˓Cos(rot1)*Sin(rot2)*Sin(rot3)) + d2*(Cos(rot1)*Cos(rot3) +→˓Sin(rot1)*Sin(rot2)*Sin(rot3)),2)))
- (Cos(rot2)*Sin(rot1)*Sqrt(Power(d1*Cos(rot2)*Cos(rot3) +→˓d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) - Cos(rot1)*Sin(rot3)) +→˓L*(Cos(rot1)*Cos(rot3)*Sin(rot2) + Sin(rot1)*Sin(rot3)),2) +
Power(d1*Cos(rot2)*Sin(rot3) + L*(-(Cos(rot3)*Sin(rot1)) +→˓Cos(rot1)*Sin(rot2)*Sin(rot3)) + d2*(Cos(rot1)*Cos(rot3) +→˓Sin(rot1)*Sin(rot2)*Sin(rot3)),2)))/
(Power(L*Cos(rot1)*Cos(rot2) + d2*Cos(rot2)*Sin(rot1) - d1*Sin(rot2),2) +→˓Power(d1*Cos(rot2)*Cos(rot3) + d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) -→˓Cos(rot1)*Sin(rot3)) + L*(Cos(rot1)*Cos(rot3)*Sin(rot2) +→˓Sin(rot1)*Sin(rot3)),
2) + Power(d1*Cos(rot2)*Sin(rot3) + L*(-(Cos(rot3)*Sin(rot1)) +→˓Cos(rot1)*Sin(rot2)*Sin(rot3)) + d2*(Cos(rot1)*Cos(rot3) +→˓Sin(rot1)*Sin(rot2)*Sin(rot3)),2))
6.6. geometry Module 157
![Page 162: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/162.jpg)
pyFAI Documentation, Release 0.15.0a0
In[47]:= CForm[D[ttht,L]]Out[47]//CForm=((L*Cos(rot1)*Cos(rot2) + d2*Cos(rot2)*Sin(rot1) -→˓d1*Sin(rot2))*(2*(Cos(rot1)*Cos(rot3)*Sin(rot2) + Sin(rot1)*Sin(rot3))*
(d1*Cos(rot2)*Cos(rot3) + d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) -→˓Cos(rot1)*Sin(rot3)) + L*(Cos(rot1)*Cos(rot3)*Sin(rot2) +→˓Sin(rot1)*Sin(rot3))) +
2*(-(Cos(rot3)*Sin(rot1)) +→˓Cos(rot1)*Sin(rot2)*Sin(rot3))*(d1*Cos(rot2)*Sin(rot3) + L*(-→˓(Cos(rot3)*Sin(rot1)) + Cos(rot1)*Sin(rot2)*Sin(rot3)) +→˓d2*(Cos(rot1)*Cos(rot3) + Sin(rot1)*Sin(rot2)*Sin(rot3)))))/
(2.*Sqrt(Power(d1*Cos(rot2)*Cos(rot3) + d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) -→˓ Cos(rot1)*Sin(rot3)) + L*(Cos(rot1)*Cos(rot3)*Sin(rot2) +→˓Sin(rot1)*Sin(rot3)),2) +
Power(d1*Cos(rot2)*Sin(rot3) + L*(-(Cos(rot3)*Sin(rot1)) +→˓Cos(rot1)*Sin(rot2)*Sin(rot3)) + d2*(Cos(rot1)*Cos(rot3) +→˓Sin(rot1)*Sin(rot2)*Sin(rot3)),2))*
(Power(L*Cos(rot1)*Cos(rot2) + d2*Cos(rot2)*Sin(rot1) - d1*Sin(rot2),2)→˓+ Power(d1*Cos(rot2)*Cos(rot3) + d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) -→˓Cos(rot1)*Sin(rot3)) +
L*(Cos(rot1)*Cos(rot3)*Sin(rot2) + Sin(rot1)*Sin(rot3)),2) +→˓Power(d1*Cos(rot2)*Sin(rot3) + L*(-(Cos(rot3)*Sin(rot1)) +→˓Cos(rot1)*Sin(rot2)*Sin(rot3)) + d2*(Cos(rot1)*Cos(rot3) +→˓Sin(rot1)*Sin(rot2)*Sin(rot3)),2)))
- (Cos(rot1)*Cos(rot2)*Sqrt(Power(d1*Cos(rot2)*Cos(rot3) +→˓d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) - Cos(rot1)*Sin(rot3)) +→˓L*(Cos(rot1)*Cos(rot3)*Sin(rot2) + Sin(rot1)*Sin(rot3)),2) +
Power(d1*Cos(rot2)*Sin(rot3) + L*(-(Cos(rot3)*Sin(rot1)) +→˓Cos(rot1)*Sin(rot2)*Sin(rot3)) + d2*(Cos(rot1)*Cos(rot3) +→˓Sin(rot1)*Sin(rot2)*Sin(rot3)),2)))/
(Power(L*Cos(rot1)*Cos(rot2) + d2*Cos(rot2)*Sin(rot1) - d1*Sin(rot2),2) +→˓Power(d1*Cos(rot2)*Cos(rot3) + d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) -→˓Cos(rot1)*Sin(rot3)) + L*(Cos(rot1)*Cos(rot3)*Sin(rot2) +→˓Sin(rot1)*Sin(rot3)),
2) + Power(d1*Cos(rot2)*Sin(rot3) + L*(-(Cos(rot3)*Sin(rot1)) +→˓Cos(rot1)*Sin(rot2)*Sin(rot3)) + d2*(Cos(rot1)*Cos(rot3) +→˓Sin(rot1)*Sin(rot2)*Sin(rot3)),2))In[48]:= CForm[D[ttht,rot1]]Out[48]//CForm=((L*Cos(rot1)*Cos(rot2) + d2*Cos(rot2)*Sin(rot1) - d1*Sin(rot2))*(2*(L*(-→˓(Cos(rot3)*Sin(rot1)*Sin(rot2)) + Cos(rot1)*Sin(rot3)) +→˓d2*(Cos(rot1)*Cos(rot3)*Sin(rot2) + Sin(rot1)*Sin(rot3)))*
(d1*Cos(rot2)*Cos(rot3) + d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) -→˓Cos(rot1)*Sin(rot3)) + L*(Cos(rot1)*Cos(rot3)*Sin(rot2) +→˓Sin(rot1)*Sin(rot3))) +
2*(d2*(-(Cos(rot3)*Sin(rot1)) + Cos(rot1)*Sin(rot2)*Sin(rot3)) + L*(-→˓(Cos(rot1)*Cos(rot3)) - Sin(rot1)*Sin(rot2)*Sin(rot3)))*
(d1*Cos(rot2)*Sin(rot3) + L*(-(Cos(rot3)*Sin(rot1)) +→˓Cos(rot1)*Sin(rot2)*Sin(rot3)) + d2*(Cos(rot1)*Cos(rot3) +→˓Sin(rot1)*Sin(rot2)*Sin(rot3)))))/
(2.*Sqrt(Power(d1*Cos(rot2)*Cos(rot3) + d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) -→˓ Cos(rot1)*Sin(rot3)) + L*(Cos(rot1)*Cos(rot3)*Sin(rot2) +→˓Sin(rot1)*Sin(rot3)),2) +
Power(d1*Cos(rot2)*Sin(rot3) + L*(-(Cos(rot3)*Sin(rot1)) +→˓Cos(rot1)*Sin(rot2)*Sin(rot3)) + d2*(Cos(rot1)*Cos(rot3) +→˓Sin(rot1)*Sin(rot2)*Sin(rot3)),2))*
(Power(L*Cos(rot1)*Cos(rot2) + d2*Cos(rot2)*Sin(rot1) - d1*Sin(rot2),2)→˓+ Power(d1*Cos(rot2)*Cos(rot3) + d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) -→˓Cos(rot1)*Sin(rot3)) +
L*(Cos(rot1)*Cos(rot3)*Sin(rot2) + Sin(rot1)*Sin(rot3)),2) +→˓Power(d1*Cos(rot2)*Sin(rot3) + L*(-(Cos(rot3)*Sin(rot1)) +→˓Cos(rot1)*Sin(rot2)*Sin(rot3)) + d2*(Cos(rot1)*Cos(rot3) +→˓Sin(rot1)*Sin(rot2)*Sin(rot3)),2)))
158 Chapter 6. pyFAI API
![Page 163: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/163.jpg)
pyFAI Documentation, Release 0.15.0a0
- ((d2*Cos(rot1)*Cos(rot2) -→˓L*Cos(rot2)*Sin(rot1))*Sqrt(Power(d1*Cos(rot2)*Cos(rot3) +→˓d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) - Cos(rot1)*Sin(rot3)) +→˓L*(Cos(rot1)*Cos(rot3)*Sin(rot2) + Sin(rot1)*Sin(rot3)),2) +
Power(d1*Cos(rot2)*Sin(rot3) + L*(-(Cos(rot3)*Sin(rot1)) +→˓Cos(rot1)*Sin(rot2)*Sin(rot3)) + d2*(Cos(rot1)*Cos(rot3) +→˓Sin(rot1)*Sin(rot2)*Sin(rot3)),2)))/
(Power(L*Cos(rot1)*Cos(rot2) + d2*Cos(rot2)*Sin(rot1) - d1*Sin(rot2),2) +→˓Power(d1*Cos(rot2)*Cos(rot3) + d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) -→˓Cos(rot1)*Sin(rot3)) + L*(Cos(rot1)*Cos(rot3)*Sin(rot2) +→˓Sin(rot1)*Sin(rot3)),
2) + Power(d1*Cos(rot2)*Sin(rot3) + L*(-(Cos(rot3)*Sin(rot1)) +→˓Cos(rot1)*Sin(rot2)*Sin(rot3)) + d2*(Cos(rot1)*Cos(rot3) +→˓Sin(rot1)*Sin(rot2)*Sin(rot3)),2))In[49]:= CForm[D[ttht,rot2]]Out[49]//CForm=((L*Cos(rot1)*Cos(rot2) + d2*Cos(rot2)*Sin(rot1) -→˓d1*Sin(rot2))*(2*(L*Cos(rot1)*Cos(rot2)*Cos(rot3) +→˓d2*Cos(rot2)*Cos(rot3)*Sin(rot1) - d1*Cos(rot3)*Sin(rot2))*
(d1*Cos(rot2)*Cos(rot3) + d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) -→˓Cos(rot1)*Sin(rot3)) + L*(Cos(rot1)*Cos(rot3)*Sin(rot2) +→˓Sin(rot1)*Sin(rot3))) +
2*(L*Cos(rot1)*Cos(rot2)*Sin(rot3) + d2*Cos(rot2)*Sin(rot1)*Sin(rot3) -→˓ d1*Sin(rot2)*Sin(rot3))*
(d1*Cos(rot2)*Sin(rot3) + L*(-(Cos(rot3)*Sin(rot1)) +→˓Cos(rot1)*Sin(rot2)*Sin(rot3)) + d2*(Cos(rot1)*Cos(rot3) +→˓Sin(rot1)*Sin(rot2)*Sin(rot3)))))/
(2.*Sqrt(Power(d1*Cos(rot2)*Cos(rot3) + d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) -→˓ Cos(rot1)*Sin(rot3)) + L*(Cos(rot1)*Cos(rot3)*Sin(rot2) +→˓Sin(rot1)*Sin(rot3)),2) +
Power(d1*Cos(rot2)*Sin(rot3) + L*(-(Cos(rot3)*Sin(rot1)) +→˓Cos(rot1)*Sin(rot2)*Sin(rot3)) + d2*(Cos(rot1)*Cos(rot3) +→˓Sin(rot1)*Sin(rot2)*Sin(rot3)),2))*
(Power(L*Cos(rot1)*Cos(rot2) + d2*Cos(rot2)*Sin(rot1) - d1*Sin(rot2),2)→˓+ Power(d1*Cos(rot2)*Cos(rot3) + d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) -→˓Cos(rot1)*Sin(rot3)) +
L*(Cos(rot1)*Cos(rot3)*Sin(rot2) + Sin(rot1)*Sin(rot3)),2) +→˓Power(d1*Cos(rot2)*Sin(rot3) + L*(-(Cos(rot3)*Sin(rot1)) +→˓Cos(rot1)*Sin(rot2)*Sin(rot3)) + d2*(Cos(rot1)*Cos(rot3) +→˓Sin(rot1)*Sin(rot2)*Sin(rot3)),2)))
- ((-(d1*Cos(rot2)) - L*Cos(rot1)*Sin(rot2) -→˓d2*Sin(rot1)*Sin(rot2))*Sqrt(Power(d1*Cos(rot2)*Cos(rot3) +→˓d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) - Cos(rot1)*Sin(rot3)) +
L*(Cos(rot1)*Cos(rot3)*Sin(rot2) + Sin(rot1)*Sin(rot3)),2) +→˓Power(d1*Cos(rot2)*Sin(rot3) + L*(-(Cos(rot3)*Sin(rot1)) +→˓Cos(rot1)*Sin(rot2)*Sin(rot3)) + d2*(Cos(rot1)*Cos(rot3) +→˓Sin(rot1)*Sin(rot2)*Sin(rot3)),2)))
/(Power(L*Cos(rot1)*Cos(rot2) + d2*Cos(rot2)*Sin(rot1) - d1*Sin(rot2),2)→˓+ Power(d1*Cos(rot2)*Cos(rot3) + d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) -→˓Cos(rot1)*Sin(rot3)) +
L*(Cos(rot1)*Cos(rot3)*Sin(rot2) + Sin(rot1)*Sin(rot3)),2) +→˓Power(d1*Cos(rot2)*Sin(rot3) + L*(-(Cos(rot3)*Sin(rot1)) +→˓Cos(rot1)*Sin(rot2)*Sin(rot3)) + d2*(Cos(rot1)*Cos(rot3) +→˓Sin(rot1)*Sin(rot2)*Sin(rot3)),2))In[50]:= CForm[D[ttht,rot3]]Out[50]//CForm=((L*Cos(rot1)*Cos(rot2) + d2*Cos(rot2)*Sin(rot1) -→˓d1*Sin(rot2))*(2*(d1*Cos(rot2)*Cos(rot3) + d2*(Cos(rot3)*Sin(rot1)*Sin(rot2)→˓- Cos(rot1)*Sin(rot3)) + L*(Cos(rot1)*Cos(rot3)*Sin(rot2) +→˓Sin(rot1)*Sin(rot3)))*
(-(d1*Cos(rot2)*Sin(rot3)) + L*(Cos(rot3)*Sin(rot1) -→˓Cos(rot1)*Sin(rot2)*Sin(rot3)) + d2*(-(Cos(rot1)*Cos(rot3)) -→˓Sin(rot1)*Sin(rot2)*Sin(rot3))) +
6.6. geometry Module 159
![Page 164: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/164.jpg)
pyFAI Documentation, Release 0.15.0a0
2*(d1*Cos(rot2)*Cos(rot3) + d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) -→˓Cos(rot1)*Sin(rot3)) + L*(Cos(rot1)*Cos(rot3)*Sin(rot2) +→˓Sin(rot1)*Sin(rot3)))*
(d1*Cos(rot2)*Sin(rot3) + L*(-(Cos(rot3)*Sin(rot1)) +→˓Cos(rot1)*Sin(rot2)*Sin(rot3)) + d2*(Cos(rot1)*Cos(rot3) +→˓Sin(rot1)*Sin(rot2)*Sin(rot3)))))/
(2.*Sqrt(Power(d1*Cos(rot2)*Cos(rot3) + d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) -→˓Cos(rot1)*Sin(rot3)) + L*(Cos(rot1)*Cos(rot3)*Sin(rot2) +→˓Sin(rot1)*Sin(rot3)),2) +
Power(d1*Cos(rot2)*Sin(rot3) + L*(-(Cos(rot3)*Sin(rot1)) +→˓Cos(rot1)*Sin(rot2)*Sin(rot3)) + d2*(Cos(rot1)*Cos(rot3) +→˓Sin(rot1)*Sin(rot2)*Sin(rot3)),2))*
(Power(L*Cos(rot1)*Cos(rot2) + d2*Cos(rot2)*Sin(rot1) - d1*Sin(rot2),2) +→˓Power(d1*Cos(rot2)*Cos(rot3) + d2*(Cos(rot3)*Sin(rot1)*Sin(rot2) -→˓Cos(rot1)*Sin(rot3)) +
L*(Cos(rot1)*Cos(rot3)*Sin(rot2) + Sin(rot1)*Sin(rot3)),2) +→˓Power(d1*Cos(rot2)*Sin(rot3) + L*(-(Cos(rot3)*Sin(rot1)) +→˓Cos(rot1)*Sin(rot2)*Sin(rot3)) + d2*(Cos(rot1)*Cos(rot3) +→˓Sin(rot1)*Sin(rot2)*Sin(rot3)),2)))
__init__(dist=1, poni1=0, poni2=0, rot1=0, rot2=0, rot3=0, pixel1=None, pixel2=None, spline-File=None, detector=None, wavelength=None)
Parameters
• dist – distance sample - detector plan (orthogonal distance, not along the beam), inmeter.
• poni1 – coordinate of the point of normal incidence along the detector’s first dimen-sion, in meter
• poni2 – coordinate of the point of normal incidence along the detector’s seconddimension, in meter
• rot1 – first rotation from sample ref to detector’s ref, in radians
• rot2 – second rotation from sample ref to detector’s ref, in radians
• rot3 – third rotation from sample ref to detector’s ref, in radians
• pixel1 (float) – Deprecated. Pixel size of the fist dimension of the detector, inmeter. If both pixel1 and pixel2 are not None, detector pixel size is overwritten. Preferdefining the detector pixel size on the provided detector object. Prefer defining thedetector pixel size on the provided detector object (detector.pixel1 = 5e-6).
• pixel2 (float) – Deprecated. Pixel size of the second dimension of the detector, inmeter. If both pixel1 and pixel2 are not None, detector pixel size is overwritten. Preferdefining the detector pixel size on the provided detector object (detector.pixel2= 5e-6).
• splineFile (str) – Deprecated. File containing the geometric distortion of thedetector. If not None, pixel1 and pixel2 are ignored and detector spline is over-written. Prefer defining the detector spline manually (detector.splineFile= "file.spline").
• detector (str or pyFAI.Detector) – name of the detector or Detector in-stance. String description is deprecated. Prefer using the result of the detector factory:pyFAI.detector_factory("eiger4m")
• wavelength (float) – Wave length used in meter
array_from_unit(shape=None, typ=’center’, unit=2th_deg, scale=True)Generate an array of position in different dimentions (R, Q, 2Theta)
Parameters
• shape (ndarray.shape) – shape of the expected array, leave it to None for safety
160 Chapter 6. pyFAI API
![Page 165: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/165.jpg)
pyFAI Documentation, Release 0.15.0a0
• typ (str) – “center”, “corner” or “delta”
• unit (pyFAI.units.Enum) – can be Q, TTH, R for now
• scale – set to False for returning the internal representation (S.I. often) which isfaster
Returns R, Q or 2Theta array depending on unit
Return type ndarray
calc_pos_zyx(d0=None, d1=None, d2=None, param=None, corners=False, use_cython=True)Calculate the position of a set of points in space in the sample’s centers referential.
This is usually used for calculating the pixel position in space.
Parameters
• d0 – altitude on the point compared to the detector (i.e. z), may be None
• d1 – position on the detector along the slow dimention (i.e. y)
• d2 – position on the detector along the fastest dimention (i.e. x)
• corners – return positions on the corners (instead of center)
Returns 3-tuple of nd-array, with dim0=along the beam, dim1=along slowest dimensiondim2=along fastest dimension
calc_transmission(t0, shape=None)Defines the absorption correction for a phosphor screen or a scintillator from t0, the normal transmis-sion of the screen.
𝐼𝑐𝑜𝑟 =𝐼𝑜𝑏𝑠(1− 𝑡0)
1− 𝑒𝑥𝑝(𝑙𝑛(𝑡0)/𝑐𝑜𝑠(𝑖𝑛𝑐𝑖𝑑𝑒𝑛𝑐𝑒))
𝑙𝑒𝑡𝑡 =1− 𝑒𝑥𝑝(𝑙𝑛(𝑡0)/𝑐𝑜𝑠(𝑖𝑛𝑐𝑖𝑑𝑒𝑛𝑐𝑒))
1− 𝑡0
See reference on: J. Appl. Cryst. (2002). 35, 356–359 G. Wu et al. CCD phosphor
Parameters
• t0 – value of the normal transmission (from 0 to 1)
• shape – shape of the array
Returns actual
calcfrom1d(tth, I, shape=None, mask=None, dim1_unit=2th_deg, correctSolidAngle=True,dummy=0.0, polarization_factor=None, polarization_axis_offset=0, dark=None,flat=None)
Computes a 2D image from a 1D integrated profile
Parameters
• tth – 1D array with radial unit, this array needs to be ordered
• I – scattering intensity, corresponding intensity
• shape – shape of the image (if not defined by the detector)
• dim1_unit – unit for the “tth” array
• correctSolidAngle –
• dummy – value for masked pixels
• polarization_factor – set to true to use previously used value
• polarization_axis_offset – axis_offset to be send to the polarizationmethod
• dark – dark current correction
6.6. geometry Module 161
![Page 166: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/166.jpg)
pyFAI Documentation, Release 0.15.0a0
• flat – flatfield corrction
Returns 2D image reconstructed
center_array(shape=None, unit=‘2th_deg’, scale=True)Generate a 2D array of the given shape with (i,j) (radial angle ) for all elements.
Parameters
• shape (2-tuple of integer) – expected shape
• unit – string like “2th_deg” or an instance of pyFAI.units.Unit
• scale – set to False for returning the internal representation (S.I. often) which isfaster
Returns 3d array with shape=(*shape,4,2) the two elements are: - dim3[0]: radial angle 2th,q, r... - dim3[1]: azimuthal angle chi
chi(d1, d2, path=’cython’)Calculate the chi (azimuthal angle) for the centre of a pixel at coordinate d1,d2 which in the lab refhas coordinate:
X1 = p1*cos(rot2)*cos(rot3) + p2*(cos(rot3)*sin(rot1)*sin(rot2) - cos(rot1)*sin(rot3))- L*(cos(rot1)*cos(rot3)*sin(rot2) + sin(rot1)*sin(rot3)) X2 = p1*cos(rot2)*sin(rot3)- L*(-(cos(rot3)*sin(rot1)) + cos(rot1)*sin(rot2)*sin(rot3)) + p2*(cos(rot1)*cos(rot3) +sin(rot1)*sin(rot2)*sin(rot3)) X3 = -(L*cos(rot1)*cos(rot2)) + p2*cos(rot2)*sin(rot1) - p1*sin(rot2)hence tan(Chi) = X2 / X1
Parameters
• d1 (float or array of them) – pixel coordinate along the 1st dimention (Cconvention)
• d2 (float or array of them) – pixel coordinate along the 2nd dimention (Cconvention)
• path – can be “tan” (i.e via numpy) or “cython”
Returns chi, the azimuthal angle in rad
chiArray(shape=None)Generate an array of azimuthal angle chi(i,j) for all elements in the detector.
Azimuthal angles are in radians
Nota: Refers to the pixel centers !
Parameters shape – the shape of the chi array
Returns the chi array as numpy.ndarray
chi_corner(d1, d2)Calculate the chi (azimuthal angle) for the corner of a pixel at coordinate d1,d2 which in the lab refhas coordinate:
X1 = p1*cos(rot2)*cos(rot3) + p2*(cos(rot3)*sin(rot1)*sin(rot2) - cos(rot1)*sin(rot3))- L*(cos(rot1)*cos(rot3)*sin(rot2) + sin(rot1)*sin(rot3)) X2 = p1*cos(rot2)*sin(rot3)- L*(-(cos(rot3)*sin(rot1)) + cos(rot1)*sin(rot2)*sin(rot3)) + p2*(cos(rot1)*cos(rot3) +sin(rot1)*sin(rot2)*sin(rot3)) X3 = -(L*cos(rot1)*cos(rot2)) + p2*cos(rot2)*sin(rot1) - p1*sin(rot2)hence tan(Chi) = X2 / X1
Parameters
• d1 (float or array of them) – pixel coordinate along the 1st dimention (Cconvention)
• d2 (float or array of them) – pixel coordinate along the 2nd dimention (Cconvention)
Returns chi, the azimuthal angle in rad
162 Chapter 6. pyFAI API
![Page 167: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/167.jpg)
pyFAI Documentation, Release 0.15.0a0
chiachi array in cache
cornerArray(*arg, **kw)decorator that deprecates the use of a function
cornerQArray(*arg, **kw)decorator that deprecates the use of a function
cornerRArray(*arg, **kw)decorator that deprecates the use of a function
cornerRd2Array(*arg, **kw)decorator that deprecates the use of a function
corner_array(shape=None, unit=None, use_cython=True, scale=True)Generate a 3D array of the given shape with (i,j) (radial angle 2th, azimuthal angle chi ) for all ele-ments.
Parameters
• shape (2-tuple of integer) – expected shape
• unit – string like “2th_deg” or an instance of pyFAI.units.Unit
• use_cython – set to False to use the slower Python path (for tests)
• scale – set to False for returning the internal representation (S.I. often) which isfaster
Returns 3d array with shape=(*shape,4,2) the two elements are: - dim3[0]: radial angle 2th,q, r... - dim3[1]: azimuthal angle chi
correct_SA_spline
cosIncidance(d1, d2, path=’cython’)Calculate the incidence angle (alpha) for current pixels (P). The poni being the point of normal inci-dence, it’s incidence angle is ${alpha} = 0$ hence $cos({alpha}) = 1$
Parameters
• d1 – 1d or 2d set of points in pixel coord
• d2 – 1d or 2d set of points in pixel coord
Returns cosine of the incidence angle
del_chia()
del_dssa()
del_qa()
del_ra()
del_ttha()
delta2Theta(shape=None)Generate a 3D array of the given shape with (i,j) with the max distance between the center and anycorner in 2 theta
Parameters shape – The shape of the detector array: 2-tuple of integer
Returns 2D-array containing the max delta angle between a pixel center and any corner in2theta-angle (rad)
deltaChi(shape=None, use_cython=True)Generate a 3D array of the given shape with (i,j) with the max distance between the center and anycorner in chi-angle (rad)
Parameters shape – The shape of the detector array: 2-tuple of integer
6.6. geometry Module 163
![Page 168: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/168.jpg)
pyFAI Documentation, Release 0.15.0a0
Returns 2D-array containing the max delta angle between a pixel center and any corner inchi-angle (rad)
deltaQ(shape=None)Generate a 2D array of the given shape with (i,j) with the max distance between the center and anycorner in q_vector unit (nm^-1)
Parameters shape – The shape of the detector array: 2-tuple of integer
Returns array 2D containing the max delta Q between a pixel center and any corner inq_vector unit (nm^-1)
deltaR(shape=None)Generate a 2D array of the given shape with (i,j) with the max distance between the center and anycorner in radius unit (mm)
Parameters shape – The shape of the detector array: 2-tuple of integer
Returns array 2D containing the max delta Q between a pixel center and any corner inq_vector unit (nm^-1)
deltaRd2(shape=None)Generate a 2D array of the given shape with (i,j) with the max distance between the center and anycorner in unit: reciprocal spacing squarred (1/nm^2)
Parameters shape – The shape of the detector array: 2-tuple of integer
Returns array 2D containing the max delta (d*)^2 between a pixel center and any corner inreciprocal spacing squarred (1/nm^2)
delta_array(shape=None, unit=‘2th_deg’, scale=False)Generate a 2D array of the given shape with (i,j) (delta-radial angle) for all elements.
Parameters
• shape (2-tuple of integer) – expected shape
• unit – string like “2th_deg” or an instance of pyFAI.units.Unit
• scale – set to False for returning the internal representation (S.I. often) which isfaster
Returns
3d array with shape=(*shape,4,2) the two elements are:
• dim3[0]: radial angle 2th, q, r...
• dim3[1]: azimuthal angle chi
diffSolidAngle(d1, d2)Calculate the solid angle of the current pixels (P) versus the PONI (C)
𝑑𝑂𝑚𝑒𝑔𝑎 =𝑂𝑚𝑒𝑔𝑎(𝑃 )
𝑂𝑚𝑒𝑔𝑎(𝐶)=
𝐴 · 𝑐𝑜𝑠(𝑎)𝑆𝑃 2
· 𝑆𝐶2
𝐴 · 𝑐𝑜𝑠(0)=
3
𝑐𝑜𝑠(𝑎)=
𝑆𝐶3
𝑆𝑃 3
𝑐𝑜𝑠(𝑎) =𝑆𝐶
𝑆𝑃
Parameters
• d1 – 1d or 2d set of points
• d2 – 1d or 2d set of points (same size&shape as d1)
Returns solid angle correction array
dist
dssasolid angle array in cache
164 Chapter 6. pyFAI API
![Page 169: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/169.jpg)
pyFAI Documentation, Release 0.15.0a0
getFit2D()Export geometry setup with the geometry of Fit2D
Returns dict with parameters compatible with fit2D geometry
getPyFAI()Export geometry setup with the geometry of PyFAI
Returns dict with the parameter-set of the PyFAI geometry
getSPD()get the SPD like parameter set: For geometry description see Peter Boesecke J.Appl.Cryst.(2007).40,s423–s427
Basically the main difference with pyFAI is the order of the axis which are flipped
Returns dictionnary with those parameters: SampleDistance: distance from sample to de-tector at the PONI (orthogonal projection) Center_1, pixel position of the PONI alongfastest axis Center_2: pixel position of the PONI along slowest axis Rot_1: rotationaround the fastest axis (x) Rot_2: rotation around the slowest axis (y) Rot_3: rotationaround the axis ORTHOGONAL to the detector plan PSize_1: pixel size in meter alongthe fastest dimention PSize_2: pixel size in meter along the slowst dimention splineFile:name of the file containing the spline BSize_1: pixel binning factor along the fastest di-mention BSize_2: pixel binning factor along the slowst dimention WaveLength: wave-length used in meter
get_chia()
get_correct_solid_angle_for_spline()
get_dist()
get_dssa()
get_mask()
get_maskfile()
get_pixel1()
get_pixel2()
get_poni1()
get_poni2()
get_qa()
get_ra()
get_rot1()
get_rot2()
get_rot3()
get_shape(shape=None)Guess what is the best shape ....
Parameters shape – force this value (2-tuple of int)
Returns 2-tuple of int
get_spline()
get_splineFile()
get_ttha()
get_wavelength()
load(filename)Load the refined parameters from a file.
6.6. geometry Module 165
![Page 170: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/170.jpg)
pyFAI Documentation, Release 0.15.0a0
Parameters filename (string) – name of the file to load
make_headers(type_=’list’)Create a configuration for the
Parameters type – can be “list” or “dict”
Returns the header with the proper format
mask
maskfile
oversampleArray(myarray)
pixel1
pixel2
polarization(shape=None, factor=None, axis_offset=0, with_checksum=False)Calculate the polarization correction accoding to the polarization factor:
•If the polarization factor is None, the correction is not applied (returns 1)
•If the polarization factor is 0 (circular polarization), the correction correspond to(1+(cos2𝜃)^2)/2
•If the polarization factor is 1 (linear horizontal polarization), there is no correction in thevertical plane and a node at 2th=90, chi=0
•If the polarization factor is -1 (linear vertical polarization), there is no correction in the hor-izontal plane and a node at 2th=90, chi=90
•If the polarization is elliptical, the polarization factor varies between -1 and +1.
The axis_offset parameter allows correction for the misalignement of the polarization plane (or ellipsemain axis) and the the detector’s X axis.
Parameters
• factor – (Ih-Iv)/(Ih+Iv): varies between 0 (circular/random polarization) and 1(where division by 0 could occure at 2th=90, chi=0)
• axis_offset – Angle between the polarization main axis and detector’s X direc-tion (in radians !!!)
Returns 2D array with polarization correction array (intensity/polarisation)
poni1
poni2
positionArray(*arg, **kw)decorator that deprecates the use of a function
position_array(shape=None, corners=False, dtype=<type ‘numpy.float64’>,use_cython=True)
Generate an array for the pixel position given the shape of the detector.
if corners is False, the coordinates of the center of the pixel is returned in an array of shape: (shape[0],shape[1], 3) where the 3 coordinates are: * z: along incident beam, * y: to the top/sky, * x: towardsthe center of the ring
If is True, the corner of each pixels are then returned. the output shape is then (shape[0], shape[1], 4,3)
Parameters
• shape – shape of the array expected
• corners – set to true to receive a (...,4,3) array of corner positions
• dtype – output format requested. Double precision is needed for fitting the geometry
166 Chapter 6. pyFAI API
![Page 171: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/171.jpg)
pyFAI Documentation, Release 0.15.0a0
• use_cython ((bool)) – set to false to test the Python path (slower)
Returns 3D coodinates as nd-array of size (...,3) or (...,3) (default)
Nota: this value is not cached and actually generated on demand (costly)
qArray(shape=None)Generate an array of the given shape with q(i,j) for all elements.
qCornerFunct(*arg, **kw)decorator that deprecates the use of a function
qFunction(d1, d2, param=None, path=’cython’)Calculates the q value for the center of a given pixel (or set of pixels) in nm-1
q = 4pi/lambda sin( 2theta / 2 )
Parameters
• d1 (scalar or array of scalar) – position(s) in pixel in first dimension (corder)
• d2 (scalar or array of scalar) – position(s) in pixel in second dimension(c order)
Returns q in in nm^(-1)
Return type float or array of floats.
qaQ array in cache
rArray(shape=None)Generate an array of the given shape with r(i,j) for all elements; The radius r being in meters.
Parameters shape – expected shape of the detector
Returns 2d array of the given shape with radius in m from beam center on detector.
rCornerFunct(*arg, **kw)decorator that deprecates the use of a function
rFunction(d1, d2, param=None, path=’cython’)Calculates the radius value for the center of a given pixel (or set of pixels) in m
r = distance to the incident beam
Parameters
• d1 (scalar or array of scalar) – position(s) in pixel in first dimension (corder)
• d2 (scalar or array of scalar) – position(s) in pixel in second dimension(c order)
Returns r in in m
Return type float or array of floats.
raR array in cache
rd2Array(shape=None)Generate an array of the given shape with (d*(i,j))^2 for all pixels.
d*^2 is the reciprocal spacing squared in inverse nm squared
Parameters shape – expected shape of the detector
Returns 2d array of the given shape with reciprocal spacing squared
6.6. geometry Module 167
![Page 172: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/172.jpg)
pyFAI Documentation, Release 0.15.0a0
read(filename)Load the refined parameters from a file.
Parameters filename (string) – name of the file to load
reset()reset most arrays that are cached: used when a parameter changes.
rot1
rot2
rot3
save(filename)Save the geometry parameters.
Parameters filename (string) – name of the file where to save the parameters
setChiDiscAtPi()Set the position of the discontinuity of the chi axis between -pi and +pi. This is the default behavour
setChiDiscAtZero()Set the position of the discontinuity of the chi axis between 0 and 2pi. By default it is between pi and-pi
setFit2D(directDist, centerX, centerY, tilt=0.0, tiltPlanRotation=0.0, pixelX=None, pixelY=None,splineFile=None)
Set the Fit2D-like parameter set: For geometry description see HPR 1996 (14) pp-240
Warning: Fit2D flips automatically images depending on their file-format. By reverse engineering wenoticed this behavour for Tiff and Mar345 images (at least). To obtaine correct result you will have toflip images using numpy.flipud.
Parameters
• direct – direct distance from sample to detector along the incident beam (in mil-limeter as in fit2d)
• tilt – tilt in degrees
• tiltPlanRotation – Rotation (in degrees) of the tilt plan arround the Z-detectoraxis * 0deg -> Y does not move, +X goes to Z<0 * 90deg -> X does not move, +Ygoes to Z<0 * 180deg -> Y does not move, +X goes to Z>0 * 270deg -> X does notmove, +Y goes to Z>0
• pixelX,pixelY – as in fit2d they ar given in micron, not in meter
• centerY (centerX,) – pixel position of the beam center
• splineFile – name of the file containing the spline
setOversampling(*arg, **kw)decorator that deprecates the use of a function
setPyFAI(**kwargs)set the geometry from a pyFAI-like dict
setSPD(SampleDistance, Center_1, Center_2, Rot_1=0, Rot_2=0, Rot_3=0, PSize_1=None,PSize_2=None, splineFile=None, BSize_1=1, BSize_2=1, WaveLength=None)
Set the SPD like parameter set: For geometry description see Peter Boesecke J.Appl.Cryst.(2007).40,s423–s427
Basically the main difference with pyFAI is the order of the axis which are flipped
Parameters
• SampleDistance – distance from sample to detector at the PONI (orthogonal pro-jection)
• Center_1 – pixel position of the PONI along fastest axis
168 Chapter 6. pyFAI API
![Page 173: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/173.jpg)
pyFAI Documentation, Release 0.15.0a0
• Center_2 – pixel position of the PONI along slowest axis
• Rot_1 – rotation around the fastest axis (x)
• Rot_2 – rotation around the slowest axis (y)
• Rot_3 – rotation around the axis ORTHOGONAL to the detector plan
• PSize_1 – pixel size in meter along the fastest dimention
• PSize_2 – pixel size in meter along the slowst dimention
• splineFile – name of the file containing the spline
• BSize_1 – pixel binning factor along the fastest dimention
• BSize_2 – pixel binning factor along the slowst dimention
• WaveLength – wavelength used
set_chia(_)
set_correct_solid_angle_for_spline(value)
set_dist(value)
set_dssa(_)
set_mask(mask)
set_maskfile(maskfile)
set_param(param)set the geometry from a 6-tuple with dist, poni1, poni2, rot1, rot2, rot3
set_pixel1(pixel1)
set_pixel2(pixel2)
set_poni1(value)
set_poni2(value)
set_qa(_)
set_ra(_)
set_rot1(value)
set_rot2(value)
set_rot3(value)
set_spline(spline)
set_splineFile(splineFile)
set_ttha(_)
set_wavelength(value)
classmethod sload(filename)A static method combining the constructor and the loader from a file
Parameters filename (string) – name of the file to load
Returns instance of Gerometry of AzimuthalIntegrator set-up with the parameter from thefile.
solidAngleArray(shape=None, order=3, absolute=False)Generate an array for the solid angle correction given the shape of the detector.
solid_angle = cos(incidence)^3
Parameters
6.6. geometry Module 169
![Page 174: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/174.jpg)
pyFAI Documentation, Release 0.15.0a0
• shape – shape of the array expected
• order – should be 3, power of the formula just obove
• absolute – the absolute solid angle is calculated as:
SA = pix1*pix2/dist^2 * cos(incidence)^3
spline
splineFile
tth(d1, d2, param=None, path=’cython’)Calculates the 2theta value for the center of a given pixel (or set of pixels)
Parameters
• d1 (scalar or array of scalar) – position(s) in pixel in first dimension (corder)
• d2 (scalar or array of scalar) – position(s) in pixel in second dimension(c order)
• path – can be “cos”, “tan” or “cython”
Returns 2theta in radians
Return type float or array of floats.
tth_corner(*arg, **kw)decorator that deprecates the use of a function
ttha2theta array in cache
twoThetaArray(shape=None)Generate an array of two-theta(i,j) in radians for each pixel in detector
the 2theta array values are in radians
Parameters shape – shape of the detector
Returns array of 2theta position in radians
wavelength
write(filename)Save the geometry parameters.
Parameters filename (string) – name of the file where to save the parameters
class pyFAI.geometry.PolarizationArray(array, checksum)Bases: tuple
arrayAlias for field number 0
checksumAlias for field number 1
class pyFAI.geometry.PolarizationDescription(polarization_factor, axis_offset)Bases: tuple
axis_offsetAlias for field number 1
polarization_factorAlias for field number 0
170 Chapter 6. pyFAI API
![Page 175: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/175.jpg)
pyFAI Documentation, Release 0.15.0a0
geometryRefinement Module
Module used to perform the geometric refinement of the model
class pyFAI.geometryRefinement.GeometryRefinement(data=None, dist=1, poni1=None,poni2=None, rot1=0, rot2=0,rot3=0, pixel1=None,pixel2=None, splineFile=None,detector=None, wavelength=None,calibrant=None)
Bases: pyFAI.azimuthalIntegrator.AzimuthalIntegrator
__init__(data=None, dist=1, poni1=None, poni2=None, rot1=0, rot2=0, rot3=0, pixel1=None,pixel2=None, splineFile=None, detector=None, wavelength=None, calibrant=None)
Parameters
• data – ndarray float64 shape = n, 3 col0: pos in dim0 (in pixels) col1: pos in dim1(in pixels) col2: ring index in calibrant object
• dist – guessed sample-detector distance (optional, in m)
• poni1 – guessed PONI coordinate along the Y axis (optional, in m)
• poni2 – guessed PONI coordinate along the X axis (optional, in m)
• rot1 – guessed tilt of the detector around the Y axis (optional, in rad)
• rot2 – guessed tilt of the detector around the X axis (optional, in rad)
• rot3 – guessed tilt of the detector around the incoming beam axis (optional, in rad)
• pixel1 – Pixel size along the vertical direction of the detector (in m), almost manda-tory
• pixel2 – Pixel size along the horizontal direction of the detector (in m), almostmandatory
• splineFile – file describing the detector as 2 cubic splines. Replaces pixel1 &pixel2
• detector – name of the detector or Detector instance. Replaces splineFile, pixel1& pixel2
• wavelength – wavelength in m (1.54e-10)
• calibrant – instance of pyFAI.calibrant.Calibrant containing the d-Spacing
anneal(maxiter=1000000)
calc_2th(rings, wavelength=None)
Parameters
• rings – indices of the rings. starts at 0 and self.dSpacing should be long enough !!!
• wavelength – wavelength in meter
chi2(param=None)
chi2_wavelength(param=None)
confidence(with_rot=True)Confidence interval obtained from the second derivative of the error function next to its minimumvalue.
Note the confidence interval increases with the number of points which is “surprizing”
Parameters with_rot – if true include rot1 & rot2 in the parameter set.
Returns std_dev, confidence
6.7. geometryRefinement Module 171
![Page 176: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/176.jpg)
pyFAI Documentation, Release 0.15.0a0
curve_fit(with_rot=True)Refine the geometry and provide confidence interval Use curve_fit from scipy.optimize to not onlyrefine the geometry (unconstrained fit)
Parameters with_rot – include rotation intro error measurment
Returns std_dev, confidence
dist_max
dist_min
get_dist_max()
get_dist_min()
get_poni1_max()
get_poni1_min()
get_poni2_max()
get_poni2_min()
get_rot1_max()
get_rot1_min()
get_rot2_max()
get_rot2_min()
get_rot3_max()
get_rot3_min()
get_wavelength_max()
get_wavelength_min()
guess_poni()PONI can be guessed by the centroid of the ring with lowest 2Theta
It may try to fit an ellipse and sometimes it works
poni1_max
poni1_min
poni2_max
poni2_min
refine1()
refine2(maxiter=1000000, fix=None)
refine2_wavelength(maxiter=1000000, fix=None)
residu1(param, d1, d2, rings)
residu1_wavelength(param, d1, d2, rings)
residu2(param, d1, d2, rings)
residu2_wavelength(param, d1, d2, rings)
residu2_wavelength_weighted(param, d1, d2, rings, weight)
residu2_weighted(param, d1, d2, rings, weight)
roca()run roca to optimise the parameter set
rot1_max
172 Chapter 6. pyFAI API
![Page 177: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/177.jpg)
pyFAI Documentation, Release 0.15.0a0
rot1_min
rot2_max
rot2_min
rot3_max
rot3_min
set_dist_max(value)
set_dist_min(value)
set_poni1_max(value)
set_poni1_min(value)
set_poni2_max(value)
set_poni2_min(value)
set_rot1_max(value)
set_rot1_min(value)
set_rot2_max(value)
set_rot2_min(value)
set_rot3_max(value)
set_rot3_min(value)
set_tolerance(value=10)Set the tolerance for a refinement of the geometry; in percent of the original value
Parameters value – Tolerance as a percentage
set_wavelength_max(value)
set_wavelength_min(value)
simplex(maxiter=1000000)
wavelength_max
wavelength_min
goniometer Module
Everything you need to calibrate a detector mounted on a goniometer or any translation table
class pyFAI.goniometer.GeometryTransformation(dist_expr, poni1_expr, poni2_expr,rot1_expr, rot2_expr, rot3_expr,param_names, pos_names=None,constants=None, content=None)
Bases: object
This class, once instanciated, behaves like a function (via the __call__ method). It is responsible for takingany input geometry and translate it into a set of parameters compatible with pyFAI, i.e. a tuple with: (dist,poni1, poni2, rot1, rot2, rot3)
This function uses numexpr for formula evaluation.
__init__(dist_expr, poni1_expr, poni2_expr, rot1_expr, rot2_expr, rot3_expr, param_names,pos_names=None, constants=None, content=None)
Constructor of the class
Parameters
6.8. goniometer Module 173
![Page 178: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/178.jpg)
pyFAI Documentation, Release 0.15.0a0
• dist_expr – formula (as string) providing with the dist
• poni1_expr – formula (as string) providing with the poni1
• poni2_expr – formula (as string) providing with the poni2
• rot1_expr – formula (as string) providing with the rot1
• rot2_expr – formula (as string) providing with the rot2
• rot3_expr – formula (as string) providing with the rot3
• param_names – list of names of the parameters used in the model
• pos_names – list of motor names for gonio with >1 degree of freedom
• constants – a dictionary with some constants the user may want to use
• content – Should be None or the name of the class (may be used in the future todispatch to multiple derivative classes)
to_dict()Export the instance representation for serialization as a dictionary
pyFAI.goniometer.GeometryTranslationalias of GeometryTransformation
class pyFAI.goniometer.Goniometer(param, trans_function, detector=’Detector’, wave-length=None, param_names=None, pos_names=None)
Bases: object
This class represents the goniometer model. Unlike this name suggests, it may include translation in additionto rotations
__init__(param, trans_function, detector=’Detector’, wavelength=None, param_names=None,pos_names=None)
Constructor of the Goniometer class.
Parameters
• param – vector of parameter to refine for defining the detector position on the go-niometer
• trans_function – function taking the parameters of the goniometer and the go-niometer position and return the 6 parameters [dist, poni1, poni2, rot1, rot2, rot3]
• detector – detector mounted on the moving arm
• wavelength – the wavelength used for the experiment
• param_names – list of names to “label” the param vector.
• pos_names – list of names to “label” the position vector of the gonio.
file_version = ‘Goniometer calibration v1.0’
get_ai(position)Creates an azimuthal integrator from the motor position
Parameters position – the goniometer position, a float for a 1 axis goniometer
Returns A freshly build AzimuthalIntegrator
get_mg(positions)Creates a MultiGeometry integrator from a list of goniometer positions.
Parameters positions – A list of goniometer positions
Returns A freshly build multi-geometry
save(filename)Save the goniometer configuration to file
174 Chapter 6. pyFAI API
![Page 179: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/179.jpg)
pyFAI Documentation, Release 0.15.0a0
Parameters filename – name of the file to save configuration to
classmethod sload(filename)
to_dict()Export the goniometer configuration to a dictionary
Returns Ordered dictionary
write(filename)Save the goniometer configuration to file
Parameters filename – name of the file to save configuration to
class pyFAI.goniometer.GoniometerRefinement(param, pos_function, trans_function,detector=’Detector’, wavelength=None,param_names=None, pos_names=None,bounds=None)
Bases: pyFAI.goniometer.Goniometer
This class allow the translation of a goniometer geometry into a pyFAI geometry using a set of parameter torefine.
__init__(param, pos_function, trans_function, detector=’Detector’, wavelength=None,param_names=None, pos_names=None, bounds=None)
Constructor of the GoniometerRefinement class
Parameters
• param – vector of parameter to refine for defining the detector position on the go-niometer
• pos_function – a function taking metadata and extracting the goniometer position
• trans_function – function taking the parameters of the goniometer and thegonopmeter position and return the 6 parameters [dist, poni1, poni2, rot1, rot2, rot3]
• detector – detector mounted on the moving arm
• wavelength – the wavelength used for the experiment
• param_names – list of names to “label” the param vector.
• pos_names – list of names to “label” the position vector of the gonio.
• bounds – list of 2-tuple with the lower and upper bound of each function
chi2(param=None)Calculate the average of the square of the error for a given parameter set
new_geometry(label, image=None, metadata=None, control_points=None, calibrant=None, ge-ometry=None)
Add a new geometry for calibration
Parameters
• label – usually a string
• image – 2D numpy array with the Debye scherrer rings
• metadata – some metadata
• control_points – an instance of ControlPoints
• calibrant – the calibrant used for calibrating
• geometry – poni or AzimuthalIntegrator instance.
refine2(method=’slsqp’, **options)Geometry refinement tool
See https://docs.scipy.org/doc/scipy-0.18.1/reference/generated/scipy.optimize.minimize.html
6.8. goniometer Module 175
![Page 180: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/180.jpg)
pyFAI Documentation, Release 0.15.0a0
Parameters
• method – name of the minimizer
• options – options for the minimizer
residu2(param)Actually performs the calulation of the average of the error squared
set_bounds(name, mini=None, maxi=None)Redefines the bounds for the refinement
Parameters
• name – name of the parameter or index in the parameter set
• mini – minimum value
• maxi – maximum value
class pyFAI.goniometer.PoniParam(dist, poni1, poni2, rot1, rot2, rot3)Bases: tuple
distAlias for field number 0
poni1Alias for field number 1
poni2Alias for field number 2
rot1Alias for field number 3
rot2Alias for field number 4
rot3Alias for field number 5
class pyFAI.goniometer.SingleGeometry(label, image=None, metadata=None,pos_function=None, control_points=None, cali-brant=None, detector=None, geometry=None)
Bases: object
This class represents a single geometry of a detector position on a goniometer arm
__init__(label, image=None, metadata=None, pos_function=None, control_points=None, cali-brant=None, detector=None, geometry=None)
Constructor of the SingleGeometry class, used for calibrating a multi-geometry setup with a movingdetector.
Parameters
• label – name of the geometry, a string or anything unmutable
• image – image with Debye-Scherrer rings as 2d numpy array
• metadata – anything which contains the goniometer position
• pos_function – a function which takes the metadata as input and returns the go-niometer arm position
• control_points – a pyFAI.control_points.ControlPoints instance (optional pa-rameter)
• calibrant – a pyFAI.calibrant.Calibrant instance. Contains the wavelength to beused (optional parameter)
176 Chapter 6. pyFAI API
![Page 181: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/181.jpg)
pyFAI Documentation, Release 0.15.0a0
• detector – a pyFAI.detectors.Detector instance or something like that Contains themask to be used (optional parameter)
• geometry – an azimuthal integrator or a ponifile (or a dict with the geometry) (op-tional parameter)
extract_cp(max_rings=None, pts_per_deg=1.0)Performs an automatic keypoint extraction and update the geometry refinement part
Parameters
• max_ring – extract at most N rings from the image
• pts_per_deg – number of control points per azimuthal degree (increase for betterprecision)
get_ai()Create a new azimuthal integrator to be used.
Returns Azimuthal Integrator instance
get_position()This method is in charge of calculating the motor position from metadata/label/...
detectors Module
Description of all detectors with a factory to instantiate them
class pyFAI.detectors.ADSC_Q210(pixel1=5.1e-05, pixel2=5.1e-05)Bases: pyFAI.detectors.Detector
ADSC Quantum 210r detector, 2x2 chips
Informations from http://www.adsc-xray.com/products/ccd-detectors/q210r-ccd-detector/
Question: how are the gaps handled ?
MAX_SHAPE = (4096, 4096)
__init__(pixel1=5.1e-05, pixel2=5.1e-05)
aliases = [’Quantum 210’]
force_pixel = True
class pyFAI.detectors.ADSC_Q270(pixel1=6.48e-05, pixel2=6.48e-05)Bases: pyFAI.detectors.Detector
ADSC Quantum 270r detector, 2x2 chips
Informations from http://www.adsc-xray.com/products/ccd-detectors/q270-ccd-detector/
Question: how are the gaps handled ?
MAX_SHAPE = (4168, 4168)
__init__(pixel1=6.48e-05, pixel2=6.48e-05)
aliases = [’Quantum 270’]
force_pixel = True
class pyFAI.detectors.ADSC_Q315(pixel1=5.1e-05, pixel2=5.1e-05)Bases: pyFAI.detectors.Detector
ADSC Quantum 315r detector, 3x3 chips
Informations from http://www.adsc-xray.com/products/ccd-detectors/q315r-ccd-detector/
Question: how are the gaps handled ?
6.9. detectors Module 177
![Page 182: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/182.jpg)
pyFAI Documentation, Release 0.15.0a0
MAX_SHAPE = (6144, 6144)
__init__(pixel1=5.1e-05, pixel2=5.1e-05)
aliases = [’Quantum 315’]
force_pixel = True
class pyFAI.detectors.ADSC_Q4(pixel1=8.2e-05, pixel2=8.2e-05)Bases: pyFAI.detectors.Detector
ADSC Quantum 4r detector, 2x2 chips
Informations from http://proteincrystallography.org/detectors/adsc.php
Question: how are the gaps handled ?
MAX_SHAPE = (2304, 2304)
__init__(pixel1=8.2e-05, pixel2=8.2e-05)
aliases = [’Quantum 4’]
force_pixel = True
class pyFAI.detectors.Aarhus(pixel1=2.5e-05, pixel2=2.5e-05, radius=0.3)Bases: pyFAI.detectors.Detector
Cylindrical detector made of a bent imaging-plate. Developped at the Danish university of Aarhus r = 1.2mor 0.3m
The image has to be laid-out horizontally
Nota: the detector is bending towards the sample, hence reducing the sample-detector distance. This is whyz<0 (or p3<0)
TODO: update cython code for 3d detectors use expand2d instead of outer product with ones
IS_FLAT = False
MAX_SHAPE = (1000, 16000)
__init__(pixel1=2.5e-05, pixel2=2.5e-05, radius=0.3)
calc_cartesian_positions(d1=None, d2=None, center=True, use_cython=True)Calculate the position of each pixel center in cartesian coordinate and in meter of a couple of coordi-nates. The half pixel offset is taken into account here !!! Adapted to Nexus detector definition
Parameters
• d1 (ndarray (1D or 2D)) – the Y pixel positions (slow dimension)
• d2 (ndarray (1D or 2D)) – the X pixel positions (fast dimension)
• center – retrieve the coordinate of the center of the pixel
• use_cython – set to False to test Python implementeation
Returns position in meter of the center of each pixels.
Return type ndarray
d1 and d2 must have the same shape, returned array will have the same shape.
force_pixel = True
get_pixel_corners(use_cython=True)Calculate the position of the corner of the pixels
This should be overwritten by class representing non-contiguous detector (Xpad, ...)
Returns 4D array containing: pixel index (slow dimension) pixel index (fast dimension)corner index (A, B, C or D), triangles or hexagons can be handled the same way vertexposition (z,y,x)
178 Chapter 6. pyFAI API
![Page 183: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/183.jpg)
pyFAI Documentation, Release 0.15.0a0
class pyFAI.detectors.Apex2(pixel1=0.00012, pixel2=0.00012)Bases: pyFAI.detectors.Detector
BrukerApex2 detector
Actually a derivative from the Fairchild detector with higher binning
DEFAULT_PIXEL1 = 6e-05
DEFAULT_PIXEL2 = 6e-05
MAX_SHAPE = (1024, 1024)
__init__(pixel1=0.00012, pixel2=0.00012)Defaults to 2x2 binning
aliases = [’ApexII’, ‘Bruker’]
force_pixel = True
class pyFAI.detectors.Basler(pixel=3.75e-06)Bases: pyFAI.detectors.Detector
Basler camera are simple CCD camara over GigaE
MAX_SHAPE = (966, 1296)
__init__(pixel=3.75e-06)
aliases = [’aca1300’]
force_pixel = True
class pyFAI.detectors.Detector(pixel1=None, pixel2=None, splineFile=None,max_shape=None)
Bases: object
Generic class representing a 2D detector
API_VERSION = ‘1.0’
HAVE_TAPER = FalseIf true a spline file is mandatory to correct the geometry
IS_CONTIGUOUS = True
IS_FLAT = True
__init__(pixel1=None, pixel2=None, splineFile=None, max_shape=None)
Parameters
• pixel1 (float) – size of the pixel in meter along the slow dimension (often Y)
• pixel2 (float) – size of the pixel in meter along the fast dimension (often X)
• splineFile (str) – path to file containing the geometric correction.
• max_shape (2-tuple of integrers) – maximum size of the detector
aliases = []
binning
calc_cartesian_positions(d1=None, d2=None, center=True, use_cython=True)Calculate the position of each pixel center in cartesian coordinate and in meter of a couple of coordi-nates. The half pixel offset is taken into account here !!! Adapted to Nexus detector definition
Parameters
• d1 (ndarray (1D or 2D)) – the Y pixel positions (slow dimension)
• d2 (ndarray (1D or 2D)) – the X pixel positions (fast dimension)
• center – retrieve the coordinate of the center of the pixel, unless gives one corner
6.9. detectors Module 179
![Page 184: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/184.jpg)
pyFAI Documentation, Release 0.15.0a0
• use_cython – set to False to test Python implementation
Returns position in meter of the center of each pixels.
Return type 3xndarray, the later being None if IS_FLAT
d1 and d2 must have the same shape, returned array will have the same shape.
pos_z is None for flat detectors
calc_mask()Method calculating the mask for a given detector
Detectors with gaps should overwrite this method with something actually calculating the mask!
Returns the mask with valid pixel to 0
Return type numpy ndarray of int8 or None
darkcurrent
classmethod factory(name, config=None)A kind of factory...
Parameters
• name (str) – name of a detector
• config (dict or JSON representation of it.) – configuration of thedetector
Returns an instance of the right detector, set-up if possible
Return type pyFAI.detectors.Detector
flatfield
force_pixel = False
classmethod from_dict(dico)Creates a brand new detector from the description of the detector as a dict
Parameters dico – JSON serializable dictionary
Returns Detector instance
getFit2D()Helper method to serialize the description of a detector using the Fit2d units
Returns representation of the detector easy to serialize
Return type dict
getPyFAI()Helper method to serialize the description of a detector using the pyFAI way with everything in S.Iunits.
Returns representation of the detector easy to serialize
Return type dict
get_binning()
get_darkcurrent()
get_darkcurrent_crc()
get_flatfield()
get_flatfield_crc()
get_mask()
get_mask_crc()
180 Chapter 6. pyFAI API
![Page 185: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/185.jpg)
pyFAI Documentation, Release 0.15.0a0
get_maskfile()
get_name()Get a meaningful name for detector
get_pixel1()
get_pixel2()
get_pixel_corners()Calculate the position of the corner of the pixels
This should be overwritten by class representing non-contiguous detector (Xpad, ...)
Precision float32 is ok: precision of 1µm for a detector size of 1m
Returns 4D array containing: pixel index (slow dimension) pixel index (fast dimension)corner index (A, B, C or D), triangles or hexagons can be handled the same way vertexposition (z,y,x)
get_splineFile()
guess_binning(data)Guess the binning/mode depending on the image shape :param data: 2-tuple with the shape of theimage or the image with a .shape attribute.
mask
maskfile
nameGet a meaningful name for detector
pixel1
pixel2
registry = {‘pilatus1m_cdte’: <class ‘pyFAI.detectors.PilatusCdTe1M’>, ‘imxpads10’: <class ‘pyFAI.detectors.ImXPadS10’>, ‘pilatus1mcdte’: <class ‘pyFAI.detectors.PilatusCdTe1M’>, ‘rayonix_mx225hs’: <class ‘pyFAI.detectors.RayonixMx225hs’>, ‘pilatus_cdte_2m’: <class ‘pyFAI.detectors.PilatusCdTe2M’>, ‘d5’: <class ‘pyFAI.detectors.Xpad_flat’>, ‘eiger_500k’: <class ‘pyFAI.detectors.Eiger500k’>, ‘rayonix_mx170-hs’: <class ‘pyFAI.detectors.RayonixMx170’>, ‘imxpad_s10’: <class ‘pyFAI.detectors.ImXPadS10’>, ‘rayonix_mx340hs’: <class ‘pyFAI.detectors.RayonixMx340hs’>, ‘condor’: <class ‘pyFAI.detectors.Fairchild’>, ‘eiger16m’: <class ‘pyFAI.detectors.Eiger16M’>, ‘pilatus_1m’: <class ‘pyFAI.detectors.Pilatus1M’>, ‘oxd_titan’: <class ‘pyFAI.detectors.Titan’>, ‘perkin_detector’: <class ‘pyFAI.detectors.Perkin’>, ‘pilatus6m’: <class ‘pyFAI.detectors.Pilatus6M’>, ‘titan_2k_x_2k’: <class ‘pyFAI.detectors.Titan’>, ‘hf_262k’: <class ‘pyFAI.detectors.HF_262k’>, ‘thales_electronics’: <class ‘pyFAI.detectors.Pixium’>, ‘rayonixlx255’: <class ‘pyFAI.detectors.RayonixLx255’>, ‘rayonixsx200’: <class ‘pyFAI.detectors.RayonixSx200’>, ‘eiger4m’: <class ‘pyFAI.detectors.Eiger4M’>, ‘rayonix_lx170’: <class ‘pyFAI.detectors.RayonixLx170’>, ‘pilatuscdte300kw’: <class ‘pyFAI.detectors.PilatusCdTe300kw’>, ‘pilatus300k’: <class ‘pyFAI.detectors.Pilatus300k’>, ‘picamv2’: <class ‘pyFAI.detectors.RaspberryPi8M’>, ‘picamv1’: <class ‘pyFAI.detectors.RaspberryPi5M’>, ‘quantum_270’: <class ‘pyFAI.detectors.ADSC_Q270’>, ‘rayonixmx300’: <class ‘pyFAI.detectors.RayonixMx300’>, ‘pilatus300kw_cdte’: <class ‘pyFAI.detectors.PilatusCdTe300kw’>, ‘rayonixlx225hs’: <class ‘pyFAI.detectors.RayonixLx255’>, ‘pilatuscdte1m’: <class ‘pyFAI.detectors.PilatusCdTe1M’>, ‘raspberrypi5m’: <class ‘pyFAI.detectors.RaspberryPi5M’>, ‘pilatus_cdte_300kw’: <class ‘pyFAI.detectors.PilatusCdTe300kw’>, ‘perkin’: <class ‘pyFAI.detectors.Perkin’>, ‘rayonixmx340hs’: <class ‘pyFAI.detectors.RayonixMx340hs’>, ‘rayonix_mx325’: <class ‘pyFAI.detectors.RayonixMx325’>, ‘picam_v2’: <class ‘pyFAI.detectors.RaspberryPi8M’>, ‘adsc_q270’: <class ‘pyFAI.detectors.ADSC_Q270’>, ‘rayonixmx170hs’: <class ‘pyFAI.detectors.RayonixMx170’>, ‘pilatus_6m’: <class ‘pyFAI.detectors.Pilatus6M’>, ‘oxdtitan’: <class ‘pyFAI.detectors.Titan’>, ‘dexela2923’: <class ‘pyFAI.detectors.Dexela2923’>, ‘xpads540flat’: <class ‘pyFAI.detectors.Xpad_flat’>, ‘titan’: <class ‘pyFAI.detectors.Titan’>, ‘aarhus’: <class ‘pyFAI.detectors.Aarhus’>, ‘rayonix_mx425hs’: <class ‘pyFAI.detectors.RayonixMx425hs’>, ‘hf_4m’: <class ‘pyFAI.detectors.HF_4M’>, ‘pilatuscdte2m’: <class ‘pyFAI.detectors.PilatusCdTe2M’>, ‘pilatuscdte300k’: <class ‘pyFAI.detectors.PilatusCdTe300k’>, ‘pilatus_1m_cdte’: <class ‘pyFAI.detectors.PilatusCdTe1M’>, ‘pilatus_300kw’: <class ‘pyFAI.detectors.Pilatus300kw’>, ‘rayonixmx170-hs’: <class ‘pyFAI.detectors.RayonixMx170’>, ‘rayonixmx300hs’: <class ‘pyFAI.detectors.RayonixMx300hs’>, ‘pixium4700detector’: <class ‘pyFAI.detectors.Pixium’>, ‘rayonixlx255-hs’: <class ‘pyFAI.detectors.RayonixLx255’>, ‘agilenttitan’: <class ‘pyFAI.detectors.Titan’>, ‘eiger500k’: <class ‘pyFAI.detectors.Eiger500k’>, ‘rayonixsx165’: <class ‘pyFAI.detectors.RayonixSx165’>, ‘pilatus100k’: <class ‘pyFAI.detectors.Pilatus100k’>, ‘rayonix_lx170-hs’: <class ‘pyFAI.detectors.RayonixLx170’>, ‘perkin_elmer’: <class ‘pyFAI.detectors.Perkin’>, ‘aca1300’: <class ‘pyFAI.detectors.Basler’>, ‘quantum315’: <class ‘pyFAI.detectors.ADSC_Q315’>, ‘quantum4’: <class ‘pyFAI.detectors.ADSC_Q4’>, ‘rayonixsx85hs’: <class ‘pyFAI.detectors.RayonixSx85hs’>, ‘eiger_4m’: <class ‘pyFAI.detectors.Eiger4M’>, ‘imxpads140’: <class ‘pyFAI.detectors.ImXPadS140’>, ‘rayonix_mx170’: <class ‘pyFAI.detectors.RayonixMx170’>, ‘pilatus300kw’: <class ‘pyFAI.detectors.Pilatus300kw’>, ‘hf-130k’: <class ‘pyFAI.detectors.HF_130K’>, ‘pilatus_100k’: <class ‘pyFAI.detectors.Pilatus100k’>, ‘rayonixsx30hs’: <class ‘pyFAI.detectors.RayonixSx30hs’>, ‘mar345’: <class ‘pyFAI.detectors.Mar345’>, ‘perkindetector’: <class ‘pyFAI.detectors.Perkin’>, ‘rayonix_mx425_hs’: <class ‘pyFAI.detectors.RayonixMx425hs’>, ‘rayonix_mx225’: <class ‘pyFAI.detectors.RayonixMx225’>, ‘eiger1m’: <class ‘pyFAI.detectors.Eiger1M’>, ‘mar_345’: <class ‘pyFAI.detectors.Mar345’>, ‘pilatus2m’: <class ‘pyFAI.detectors.Pilatus2M’>, ‘hf_9m’: <class ‘pyFAI.detectors.HF_9M’>, ‘rayonixlx170hs’: <class ‘pyFAI.detectors.RayonixLx170’>, ‘hf-1m’: <class ‘pyFAI.detectors.HF_1M’>, ‘eiger_1m’: <class ‘pyFAI.detectors.Eiger1M’>, ‘rayonix_lx170_hs’: <class ‘pyFAI.detectors.RayonixLx170’>, ‘rayonixmx170’: <class ‘pyFAI.detectors.RayonixMx170’>, ‘pilatus2mcdte’: <class ‘pyFAI.detectors.PilatusCdTe2M’>, ‘mar165’: <class ‘pyFAI.detectors.RayonixSx165’>, ‘pilatus200k’: <class ‘pyFAI.detectors.Pilatus200k’>, ‘pilatus_200k’: <class ‘pyFAI.detectors.Pilatus200k’>, ‘hf_2m’: <class ‘pyFAI.detectors.HF_2M’>, ‘titan2kx2k’: <class ‘pyFAI.detectors.Titan’>, ‘pilatus_cdte_1m’: <class ‘pyFAI.detectors.PilatusCdTe1M’>, ‘hf-9.4m’: <class ‘pyFAI.detectors.HF_9M’>, ‘fairchild_condor_486:90’: <class ‘pyFAI.detectors.Fairchild’>, ‘hf-262k’: <class ‘pyFAI.detectors.HF_262k’>, ‘xpad_flat’: <class ‘pyFAI.detectors.Xpad_flat’>, ‘quantum_315’: <class ‘pyFAI.detectors.ADSC_Q315’>, ‘eiger_16m’: <class ‘pyFAI.detectors.Eiger16M’>, ‘pilatus_300k’: <class ‘pyFAI.detectors.Pilatus300k’>, ‘raspberrypi8m’: <class ‘pyFAI.detectors.RaspberryPi8M’>, ‘pilatus1m’: <class ‘pyFAI.detectors.Pilatus1M’>, ‘xpad_s540_flat’: <class ‘pyFAI.detectors.Xpad_flat’>, ‘pixium_4700_detector’: <class ‘pyFAI.detectors.Pixium’>, ‘basler’: <class ‘pyFAI.detectors.Basler’>, ‘pilatus2m_cdte’: <class ‘pyFAI.detectors.PilatusCdTe2M’>, ‘rayonix_sx200’: <class ‘pyFAI.detectors.RayonixSx200’>, ‘quantum270’: <class ‘pyFAI.detectors.ADSC_Q270’>, ‘dexela_2923’: <class ‘pyFAI.detectors.Dexela2923’>, ‘mar3450’: <class ‘pyFAI.detectors.Mar345’>, ‘pixium’: <class ‘pyFAI.detectors.Pixium’>, ‘fairchild’: <class ‘pyFAI.detectors.Fairchild’>, ‘rayonixmx225hs’: <class ‘pyFAI.detectors.RayonixMx225hs’>, ‘apexii’: <class ‘pyFAI.detectors.Apex2’>, ‘quantum_210’: <class ‘pyFAI.detectors.ADSC_Q210’>, ‘bruker’: <class ‘pyFAI.detectors.Apex2’>, ‘thaleselectronics’: <class ‘pyFAI.detectors.Pixium’>, ‘pilatus300kwcdte’: <class ‘pyFAI.detectors.PilatusCdTe300kw’>, ‘pilatus_2m’: <class ‘pyFAI.detectors.Pilatus2M’>, ‘rayonixmx425hs’: <class ‘pyFAI.detectors.RayonixMx425hs’>, ‘imxpads70’: <class ‘pyFAI.detectors.ImXPadS70’>, ‘pilatus_300k_cdte’: <class ‘pyFAI.detectors.PilatusCdTe300k’>, ‘rayonix_sx30hs’: <class ‘pyFAI.detectors.RayonixSx30hs’>, ‘eiger9m’: <class ‘pyFAI.detectors.Eiger9M’>, ‘agilent_titan’: <class ‘pyFAI.detectors.Titan’>, ‘rayonixlx255hs’: <class ‘pyFAI.detectors.RayonixLx255’>, ‘rayonix133’: <class ‘pyFAI.detectors.Rayonix133’>, ‘rayonix_lx255’: <class ‘pyFAI.detectors.RayonixLx255’>, ‘rayonixlx170-hs’: <class ‘pyFAI.detectors.RayonixLx170’>, ‘perkinelmer’: <class ‘pyFAI.detectors.Perkin’>, ‘rayonix’: <class ‘pyFAI.detectors.Rayonix’>, ‘rayonix_sx165’: <class ‘pyFAI.detectors.RayonixSx165’>, ‘rayonix_mx300hs’: <class ‘pyFAI.detectors.RayonixMx300hs’>, ‘rayonix_lx255-hs’: <class ‘pyFAI.detectors.RayonixLx255’>, ‘adsc_q4’: <class ‘pyFAI.detectors.ADSC_Q4’>, ‘rayonixmx225’: <class ‘pyFAI.detectors.RayonixMx225’>, ‘rayonix_sx30_hs’: <class ‘pyFAI.detectors.RayonixSx30hs’>, ‘apex2’: <class ‘pyFAI.detectors.Apex2’>, ‘hf-2.4m’: <class ‘pyFAI.detectors.HF_2M’>, ‘pilatus_cdte_300k’: <class ‘pyFAI.detectors.PilatusCdTe300k’>, ‘detector’: <class ‘pyFAI.detectors.Detector’>, ‘pilatus_2m_cdte’: <class ‘pyFAI.detectors.PilatusCdTe2M’>, ‘picam_v1’: <class ‘pyFAI.detectors.RaspberryPi5M’>, ‘imxpad_s140’: <class ‘pyFAI.detectors.ImXPadS140’>, ‘fairchildcondor486:90’: <class ‘pyFAI.detectors.Fairchild’>, ‘adsc_q210’: <class ‘pyFAI.detectors.ADSC_Q210’>, ‘pilatus300kcdte’: <class ‘pyFAI.detectors.PilatusCdTe300k’>, ‘rayonixlx170’: <class ‘pyFAI.detectors.RayonixLx170’>, ‘pilatus300k_cdte’: <class ‘pyFAI.detectors.PilatusCdTe300k’>, ‘rayonix_sx85_hs’: <class ‘pyFAI.detectors.RayonixSx85hs’>, ‘rayonix_mx170_hs’: <class ‘pyFAI.detectors.RayonixMx170’>, ‘rayonix_lx_255hs’: <class ‘pyFAI.detectors.RayonixLx255’>, ‘quantum210’: <class ‘pyFAI.detectors.ADSC_Q210’>, ‘hf_1m’: <class ‘pyFAI.detectors.HF_1M’>, ‘rayonix_mx225_hs’: <class ‘pyFAI.detectors.RayonixMx225hs’>, ‘mar133’: <class ‘pyFAI.detectors.Rayonix133’>, ‘frelon’: <class ‘pyFAI.detectors.FReLoN’>, ‘hf_130k’: <class ‘pyFAI.detectors.HF_130K’>, ‘pilatus_300kw_cdte’: <class ‘pyFAI.detectors.PilatusCdTe300kw’>, ‘imxpad_s70’: <class ‘pyFAI.detectors.ImXPadS70’>, ‘adsc_q315’: <class ‘pyFAI.detectors.ADSC_Q315’>, ‘rayonixmx325’: <class ‘pyFAI.detectors.RayonixMx325’>, ‘rayonix_sx85hs’: <class ‘pyFAI.detectors.RayonixSx85hs’>, ‘eiger_9m’: <class ‘pyFAI.detectors.Eiger9M’>, ‘rayonix_mx300_hs’: <class ‘pyFAI.detectors.RayonixMx300hs’>, ‘hf-4m’: <class ‘pyFAI.detectors.HF_4M’>, ‘rayonix_mx300’: <class ‘pyFAI.detectors.RayonixMx300’>, ‘quantum_4’: <class ‘pyFAI.detectors.ADSC_Q4’>}
save(filename)Saves the detector description into a NeXus file, adapted from: http://download.nexusformat.org/sphinx/classes/base_classes/NXdetector.html Main differences:
•differentiate pixel center from pixel corner offsets
•store all offsets are ndarray according to slow/fast dimension (not x, y)
Parameters filename – name of the file on the disc
setFit2D(**kwarg)Twin method of getFit2D: setup a detector instance according to a description
Parameters kwarg – dictionary containing pixel1, pixel2 and splineFile
setPyFAI(**kwarg)Twin method of getPyFAI: setup a detector instance according to a description
Parameters kwarg – dictionary containing detector, pixel1, pixel2 and splineFile
set_binning(bin_size=(1, 1))Set the “binning” of the detector,
Parameters bin_size ((int, int)) – binning as integer or tuple of integers.
set_config(config)Sets the configuration of the detector. This implies:
•Orientation: integers
•Binning
•ROI
6.9. detectors Module 181
![Page 186: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/186.jpg)
pyFAI Documentation, Release 0.15.0a0
The configuration is either a python dictionary or a JSON string or a file containing this JSON config-uration
keys in that dictionary are :
•“orientation”: integers from 0 to 7
•“binning”: integer or 2-tuple of integers. If only one integer is provided,
•“offset”: coordinate (in pixels) of the start of the detector
set_darkcurrent(dark)
set_darkfiles(files=None, method=’mean’)
Parameters
• files (str or list(str) or None) – file(s) used to compute the dark.
• method (str) – method used to compute the dark, “mean” or “median”
Set the dark current from one or mutliple files, avaraged according to the method provided
set_dx(dx=None)set the pixel-wise displacement along X (dim2):
set_dy(dy=None)set the pixel-wise displacement along Y (dim1):
set_flatfield(flat)
set_flatfiles(files, method=’mean’)
Parameters
• files (str or list(str) or None) – file(s) used to compute the flat-field.
• method (str) – method used to compute the dark, “mean” or “median”
Set the flat field from one or mutliple files, averaged according to the method provided
set_mask(mask)
set_maskfile(maskfile)
set_pixel1(value)
set_pixel2(value)
set_splineFile(splineFile)
splineFile
uniform_pixel = True
class pyFAI.detectors.DetectorMeta(name, bases, dct)Bases: type
Metaclass used to register all detector classes inheriting from Detector
__init__(name, bases, dct)
class pyFAI.detectors.Dexela2923(pixel1=7.5e-05, pixel2=7.5e-05)Bases: pyFAI.detectors.Detector
Dexela CMOS family detector
MAX_SHAPE = (3888, 3072)
__init__(pixel1=7.5e-05, pixel2=7.5e-05)
aliases = [’Dexela 2923’]
force_pixel = True
182 Chapter 6. pyFAI API
![Page 187: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/187.jpg)
pyFAI Documentation, Release 0.15.0a0
class pyFAI.detectors.Eiger(pixel1=7.5e-05, pixel2=7.5e-05, max_shape=None, mod-ule_size=None)
Bases: pyFAI.detectors.Detector
Eiger detector: generic description containing mask algorithm
MODULE_GAP = (37, 10)
MODULE_SIZE = (514, 1030)
__init__(pixel1=7.5e-05, pixel2=7.5e-05, max_shape=None, module_size=None)
calc_cartesian_positions(d1=None, d2=None, center=True, use_cython=True)Calculate the position of each pixel center in cartesian coordinate and in meter of a couple of coordi-nates. The half pixel offset is taken into account here !!!
Parameters
• d1 (ndarray (1D or 2D)) – the Y pixel positions (slow dimension)
• d2 (ndarray (1D or 2D)) – the X pixel positions (fast dimension)
Returns p1, p2 position in meter of the center of each pixels.
Return type 2-tuple of numpy.ndarray
d1 and d2 must have the same shape, returned array will have the same shape.
calc_mask()Returns a generic mask for Pilatus detectors...
force_pixel = True
class pyFAI.detectors.Eiger16M(pixel1=7.5e-05, pixel2=7.5e-05, max_shape=None, mod-ule_size=None)
Bases: pyFAI.detectors.Eiger
Eiger 16M detector
MAX_SHAPE = (4371, 4150)
aliases = [’Eiger 16M’]
class pyFAI.detectors.Eiger1M(pixel1=7.5e-05, pixel2=7.5e-05, max_shape=None, mod-ule_size=None)
Bases: pyFAI.detectors.Eiger
Eiger 1M detector
MAX_SHAPE = (1065, 1030)
aliases = [’Eiger 1M’]
class pyFAI.detectors.Eiger4M(pixel1=7.5e-05, pixel2=7.5e-05, max_shape=None, mod-ule_size=None)
Bases: pyFAI.detectors.Eiger
Eiger 4M detector
MAX_SHAPE = (2167, 2070)
aliases = [’Eiger 4M’]
class pyFAI.detectors.Eiger500k(pixel1=7.5e-05, pixel2=7.5e-05, max_shape=None, mod-ule_size=None)
Bases: pyFAI.detectors.Eiger
Eiger 1M detector
MAX_SHAPE = (512, 1030)
aliases = [’Eiger 500k’]
6.9. detectors Module 183
![Page 188: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/188.jpg)
pyFAI Documentation, Release 0.15.0a0
class pyFAI.detectors.Eiger9M(pixel1=7.5e-05, pixel2=7.5e-05, max_shape=None, mod-ule_size=None)
Bases: pyFAI.detectors.Eiger
Eiger 9M detector
MAX_SHAPE = (3269, 3110)
aliases = [’Eiger 9M’]
class pyFAI.detectors.FReLoN(splineFile=None)Bases: pyFAI.detectors.Detector
FReLoN detector: The spline is mandatory to correct for geometric distortion of the taper
TODO: create automatically a mask that removes pixels out of the “valid reagion”
HAVE_TAPER = True
MAX_SHAPE = (2048, 2048)
__init__(splineFile=None)
calc_mask()Returns a generic mask for Frelon detectors... All pixels which (center) turns to be out of the validregion are by default discarded
class pyFAI.detectors.Fairchild(pixel1=1.5e-05, pixel2=1.5e-05)Bases: pyFAI.detectors.Detector
Fairchild Condor 486:90 detector
MAX_SHAPE = (4096, 4096)
__init__(pixel1=1.5e-05, pixel2=1.5e-05)
aliases = [’Fairchild’, ‘Condor’, ‘Fairchild Condor 486:90’]
force_pixel = True
uniform_pixel = True
class pyFAI.detectors.HF_130K(pixel1=0.00015, pixel2=0.00015)Bases: pyFAI.detectors.Detector
ADSC HF-130K 1 module
Informations from http://www.adsc-xray.com/products/pixel-array-detectors/hf-130k/
MAX_SHAPE = (256, 512)
__init__(pixel1=0.00015, pixel2=0.00015)
aliases = [’HF-130k’]
force_pixel = True
class pyFAI.detectors.HF_1M(pixel1=0.00015, pixel2=0.00015)Bases: pyFAI.detectors.Detector
ADSC HF-1M 2x4 modules
Informations from http://www.adsc-xray.com/products/pixel-array-detectors/hf-1m/
Nota: gaps between modules is not known/described
MAX_SHAPE = (1024, 1024)
__init__(pixel1=0.00015, pixel2=0.00015)
aliases = [’HF-1M’]
force_pixel = True
184 Chapter 6. pyFAI API
![Page 189: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/189.jpg)
pyFAI Documentation, Release 0.15.0a0
class pyFAI.detectors.HF_262k(pixel1=0.00015, pixel2=0.00015)Bases: pyFAI.detectors.Detector
ADSC HF-262k 2 module
Informations from http://www.adsc-xray.com/products/pixel-array-detectors/hf-262k/
Nota: gaps between modules is not known/described
MAX_SHAPE = (512, 512)
__init__(pixel1=0.00015, pixel2=0.00015)
aliases = [’HF-262k’]
force_pixel = True
class pyFAI.detectors.HF_2M(pixel1=0.00015, pixel2=0.00015)Bases: pyFAI.detectors.Detector
ADSC HF-1M 3x6 modules
Informations from http://www.adsc-xray.com/products/pixel-array-detectors/hf-2.4m/
Nota: gaps between modules is not known/described
MAX_SHAPE = (1536, 1536)
__init__(pixel1=0.00015, pixel2=0.00015)
aliases = [’HF-2.4M’]
force_pixel = True
class pyFAI.detectors.HF_4M(pixel1=0.00015, pixel2=0.00015)Bases: pyFAI.detectors.Detector
ADSC HF-4M 4x8 modules
Informations from http://www.adsc-xray.com/products/pixel-array-detectors/hf-4m/
MAX_SHAPE = (2048, 2048)
__init__(pixel1=0.00015, pixel2=0.00015)
aliases = [’HF-4M’]
force_pixel = True
class pyFAI.detectors.HF_9M(pixel1=0.00015, pixel2=0.00015)Bases: pyFAI.detectors.Detector
ADSC HF-130K 1 module
Informations from http://www.adsc-xray.com/products/pixel-array-detectors/hf-9-4m/
MAX_SHAPE = (3072, 3072)
__init__(pixel1=0.00015, pixel2=0.00015)
aliases = [’HF-9.4M’]
force_pixel = True
class pyFAI.detectors.ImXPadS10(pixel1=0.00013, pixel2=0.00013, max_shape=None, mod-ule_size=None)
Bases: pyFAI.detectors.Detector
ImXPad detector: ImXPad s10 detector with 1x1modules
BORDER_SIZE_RELATIVE = 2.5
MAX_SHAPE = (120, 80)
MODULE_SIZE = (120, 80)
6.9. detectors Module 185
![Page 190: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/190.jpg)
pyFAI Documentation, Release 0.15.0a0
PIXEL_SIZE = (0.00013, 0.00013)
__init__(pixel1=0.00013, pixel2=0.00013, max_shape=None, module_size=None)
aliases = [’Imxpad S10’]
calc_cartesian_positions(d1=None, d2=None, center=True, use_cython=True)Calculate the position of each pixel center in cartesian coordinate and in meter of a couple of coordi-nates. The half pixel offset is taken into account here !!!
Parameters
• d1 (ndarray (1D or 2D)) – the Y pixel positions (slow dimension)
• d2 (ndarray (1D or 2D)) – the X pixel positions (fast dimension)
Returns position in meter of the center of each pixels.
Return type ndarray
d1 and d2 must have the same shape, returned array will have the same shape.
calc_mask()Calculate the mask
calc_pixels_edges()Calculate the position of the pixel edges
force_pixel = True
get_pixel_corners(d1=None, d2=None)Calculate the position of the corner of the pixels
This should be overwritten by class representing non-contiguous detector (Xpad, ...)
Precision float32 is ok: precision of 1µm for a detector size of 1m
Returns 4D array containing: pixel index (slow dimension) pixel index (fast dimension)corner index (A, B, C or D), triangles or hexagons can be handled the same way vertexposition (z,y,x)
uniform_pixel = False
class pyFAI.detectors.ImXPadS140(pixel1=0.00013, pixel2=0.00013)Bases: pyFAI.detectors.ImXPadS10
ImXPad detector: ImXPad s140 detector with 2x7modules
BORDER_PIXEL_SIZE_RELATIVE = 2.5
MAX_SHAPE = (240, 560)
MODULE_SIZE = (120, 80)
PIXEL_SIZE = (0.00013, 0.00013)
__init__(pixel1=0.00013, pixel2=0.00013)
aliases = [’Imxpad S140’]
force_pixel = True
class pyFAI.detectors.ImXPadS70(pixel1=0.00013, pixel2=0.00013)Bases: pyFAI.detectors.ImXPadS10
ImXPad detector: ImXPad s70 detector with 1x7modules
BORDER_SIZE_RELATIVE = 2.5
MAX_SHAPE = (120, 560)
MODULE_SIZE = (120, 80)
PIXEL_EDGES = None
186 Chapter 6. pyFAI API
![Page 191: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/191.jpg)
pyFAI Documentation, Release 0.15.0a0
PIXEL_SIZE = (0.00013, 0.00013)
__init__(pixel1=0.00013, pixel2=0.00013)
aliases = [’Imxpad S70’]
force_pixel = True
class pyFAI.detectors.Mar345(pixel1=0.0001, pixel2=0.0001)Bases: pyFAI.detectors.Detector
Mar345 Imaging plate detector
In this detector, pixels are always square The valid image size are 2300, 2000, 1600, 1200, 3450, 3000,2400, 1800
MAX_SHAPE = (3450, 3450)
VALID_SIZE = {2000: 0.00015, 1600: 0.00015, 3000: 0.0001, 2400: 0.0001, 3450: 0.0001, 1200: 0.00015, 2300: 0.00015, 1800: 0.0001}
__init__(pixel1=0.0001, pixel2=0.0001)
aliases = [’MAR 345’, ‘Mar3450’]
calc_mask()
force_pixel = True
guess_binning(data)Guess the binning/mode depending on the image shape :param data: 2-tuple with the shape of theimage or the image with a .shape attribute.
class pyFAI.detectors.NexusDetector(filename=None)Bases: pyFAI.detectors.Detector
Class representing a 2D detector loaded from a NeXus file
__init__(filename=None)
getFit2D()Helper method to serialize the description of a detector using the Fit2d units
Returns representation of the detector easy to serialize
Return type dict
getPyFAI()Helper method to serialize the description of a detector using the pyFAI way with everything in S.Iunits.
Returns representation of the detector easy to serialize
Return type dict
load(filename)Loads the detector description from a NeXus file, adapted from: http://download.nexusformat.org/sphinx/classes/base_classes/NXdetector.html
Parameters filename – name of the file on the disk
classmethod sload(filename)Instantiate the detector description from a NeXus file, adapted from: http://download.nexusformat.org/sphinx/classes/base_classes/NXdetector.html
Parameters filename – name of the file on the disk
Returns Detector instance
class pyFAI.detectors.Perkin(pixel1=0.0002, pixel2=0.0002)Bases: pyFAI.detectors.Detector
Perkin detector
6.9. detectors Module 187
![Page 192: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/192.jpg)
pyFAI Documentation, Release 0.15.0a0
DEFAULT_PIXEL1 = 0.0002
DEFAULT_PIXEL2 = 0.0002
MAX_SHAPE = (4096, 4096)
__init__(pixel1=0.0002, pixel2=0.0002)
aliases = [’Perkin detector’, ‘Perkin Elmer’]
force_pixel = True
class pyFAI.detectors.Pilatus(pixel1=0.000172, pixel2=0.000172, max_shape=None, mod-ule_size=None, x_offset_file=None, y_offset_file=None)
Bases: pyFAI.detectors.Detector
Pilatus detector: generic description containing mask algorithm
Sub-classed by Pilatus1M, Pilatus2M and Pilatus6M
MODULE_GAP = (17, 7)
MODULE_SIZE = (195, 487)
__init__(pixel1=0.000172, pixel2=0.000172, max_shape=None, module_size=None,x_offset_file=None, y_offset_file=None)
calc_cartesian_positions(d1=None, d2=None, center=True, use_cython=True)Calculate the position of each pixel center in cartesian coordinate and in meter of a couple of coordi-nates. The half pixel offset is taken into account here !!!
Parameters
• d1 (ndarray (1D or 2D)) – the Y pixel positions (slow dimension)
• d2 (ndarray (1D or 2D)) – the X pixel positions (fast dimension)
Returns position in meter of the center of each pixels.
Return type ndarray
d1 and d2 must have the same shape, returned array will have the same shape.
calc_mask()Returns a generic mask for Pilatus detectors...
force_pixel = True
get_splineFile()
set_splineFile(splineFile=None)In this case splinefile is a couple filenames
splineFile
class pyFAI.detectors.Pilatus100k(pixel1=0.000172, pixel2=0.000172, max_shape=None,module_size=None, x_offset_file=None,y_offset_file=None)
Bases: pyFAI.detectors.Pilatus
Pilatus 100k detector
MAX_SHAPE = (195, 487)
aliases = [’Pilatus 100k’]
class pyFAI.detectors.Pilatus1M(pixel1=0.000172, pixel2=0.000172, max_shape=None, mod-ule_size=None, x_offset_file=None, y_offset_file=None)
Bases: pyFAI.detectors.Pilatus
Pilatus 1M detector
MAX_SHAPE = (1043, 981)
188 Chapter 6. pyFAI API
![Page 193: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/193.jpg)
pyFAI Documentation, Release 0.15.0a0
aliases = [’Pilatus 1M’]
class pyFAI.detectors.Pilatus200k(pixel1=0.000172, pixel2=0.000172, max_shape=None,module_size=None, x_offset_file=None,y_offset_file=None)
Bases: pyFAI.detectors.Pilatus
Pilatus 200k detector
MAX_SHAPE = (407, 487)
aliases = [’Pilatus 200k’]
class pyFAI.detectors.Pilatus2M(pixel1=0.000172, pixel2=0.000172, max_shape=None, mod-ule_size=None, x_offset_file=None, y_offset_file=None)
Bases: pyFAI.detectors.Pilatus
Pilatus 2M detector
MAX_SHAPE = (1679, 1475)
aliases = [’Pilatus 2M’]
class pyFAI.detectors.Pilatus300k(pixel1=0.000172, pixel2=0.000172, max_shape=None,module_size=None, x_offset_file=None,y_offset_file=None)
Bases: pyFAI.detectors.Pilatus
Pilatus 300k detector
MAX_SHAPE = (619, 487)
aliases = [’Pilatus 300k’]
class pyFAI.detectors.Pilatus300kw(pixel1=0.000172, pixel2=0.000172, max_shape=None,module_size=None, x_offset_file=None,y_offset_file=None)
Bases: pyFAI.detectors.Pilatus
Pilatus 300k-wide detector
MAX_SHAPE = (195, 1475)
aliases = [’Pilatus 300kw’]
class pyFAI.detectors.Pilatus6M(pixel1=0.000172, pixel2=0.000172, max_shape=None, mod-ule_size=None, x_offset_file=None, y_offset_file=None)
Bases: pyFAI.detectors.Pilatus
Pilatus 6M detector
MAX_SHAPE = (2527, 2463)
aliases = [’Pilatus 6M’]
class pyFAI.detectors.PilatusCdTe(pixel1=0.000172, pixel2=0.000172, max_shape=None,module_size=None, x_offset_file=None,y_offset_file=None)
Bases: pyFAI.detectors.Pilatus
Pilatus CdTe detector: Like the Pilatus with an extra 3 pixel in the middle of every module (vertically)
calc_mask()Returns a generic mask for Pilatus detectors...
class pyFAI.detectors.PilatusCdTe1M(pixel1=0.000172, pixel2=0.000172, max_shape=None,module_size=None, x_offset_file=None,y_offset_file=None)
Bases: pyFAI.detectors.PilatusCdTe
Pilatus CdTe 1M detector
6.9. detectors Module 189
![Page 194: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/194.jpg)
pyFAI Documentation, Release 0.15.0a0
MAX_SHAPE = (1043, 981)
aliases = [’Pilatus CdTe 1M’, ‘Pilatus 1M CdTe’, ‘Pilatus1M CdTe’, ‘Pilatus1MCdTe’]
class pyFAI.detectors.PilatusCdTe2M(pixel1=0.000172, pixel2=0.000172, max_shape=None,module_size=None, x_offset_file=None,y_offset_file=None)
Bases: pyFAI.detectors.PilatusCdTe
Pilatus CdTe 2M detector
MAX_SHAPE = (1679, 1475)
aliases = [’Pilatus CdTe 2M’, ‘Pilatus 2M CdTe’, ‘Pilatus2M CdTe’, ‘Pilatus2MCdTe’]
class pyFAI.detectors.PilatusCdTe300k(pixel1=0.000172, pixel2=0.000172,max_shape=None, module_size=None,x_offset_file=None, y_offset_file=None)
Bases: pyFAI.detectors.PilatusCdTe
Pilatus CdTe 300k detector
MAX_SHAPE = (619, 487)
aliases = [’Pilatus CdTe 300k’, ‘Pilatus 300k CdTe’, ‘Pilatus300k CdTe’, ‘Pilatus300kCdTe’]
class pyFAI.detectors.PilatusCdTe300kw(pixel1=0.000172, pixel2=0.000172,max_shape=None, module_size=None,x_offset_file=None, y_offset_file=None)
Bases: pyFAI.detectors.PilatusCdTe
Pilatus CdTe 300k-wide detector
MAX_SHAPE = (195, 1475)
aliases = [’Pilatus CdTe 300kw’, ‘Pilatus 300kw CdTe’, ‘Pilatus300kw CdTe’, ‘Pilatus300kwCdTe’]
class pyFAI.detectors.Pixium(pixel1=0.000308, pixel2=0.000308)Bases: pyFAI.detectors.Detector
PIXIUM 4700 detector
High energy X ray diffraction using the Pixium 4700 flat panel detector J E Daniels, M Drakopoulos, et al.;Journal of Synchrotron Radiation 16(Pt 4):463-8 · August 2009
DEFAULT_PIXEL1 = 0.000154
DEFAULT_PIXEL2 = 0.000154
MAX_SHAPE = (1910, 2480)
__init__(pixel1=0.000308, pixel2=0.000308)Defaults to 2x2 binning
aliases = [’Pixium 4700 detector’, ‘Thales Electronics’]
force_pixel = True
class pyFAI.detectors.RaspberryPi5M(pixel1=1.4e-06, pixel2=1.4e-06)Bases: pyFAI.detectors.Detector
5 Mpix detector from Raspberry Pi
MAX_SHAPE = (1944, 2592)
__init__(pixel1=1.4e-06, pixel2=1.4e-06)
aliases = [’Picam v1’]
force_pixel = True
190 Chapter 6. pyFAI API
![Page 195: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/195.jpg)
pyFAI Documentation, Release 0.15.0a0
class pyFAI.detectors.RaspberryPi8M(pixel1=1.12e-06, pixel2=1.12e-06)Bases: pyFAI.detectors.Detector
8 Mpix detector from Raspberry Pi
MAX_SHAPE = (2464, 3280)
__init__(pixel1=1.12e-06, pixel2=1.12e-06)
aliases = [’Picam v2’]
force_pixel = True
class pyFAI.detectors.Rayonix(pixel1=3.2e-05, pixel2=3.2e-05)Bases: pyFAI.detectors.Detector
BINNED_PIXEL_SIZE = {1: 3.2e-05}
MAX_SHAPE = (4096, 4096)
__init__(pixel1=3.2e-05, pixel2=3.2e-05)
binning
force_pixel = True
get_binning()
guess_binning(data)Guess the binning/mode depending on the image shape :param data: 2-tuple with the shape of theimage or the image with a .shape attribute.
set_binning(bin_size=(1, 1))Set the “binning” of the detector,
Parameters bin_size (int or (int, int)) – set the binning of the detector
class pyFAI.detectors.Rayonix133(pixel1=6.4e-05, pixel2=6.4e-05)Bases: pyFAI.detectors.Rayonix
Rayonix 133 2D CCD detector detector also known as mar133
Personnal communication from M. Blum
What should be the default binning factor for those cameras ?
Circular detector
BINNED_PIXEL_SIZE = {8: 0.000256, 1: 3.2e-05, 2: 6.4e-05, 4: 0.000128}
MAX_SHAPE = (4096, 4096)
__init__(pixel1=6.4e-05, pixel2=6.4e-05)
aliases = [’MAR133’]
calc_mask()Circular mask
force_pixel = True
class pyFAI.detectors.RayonixLx170(pixel1=4.42708e-05, pixel2=4.42708e-05)Bases: pyFAI.detectors.Rayonix
Rayonix lx170 2d CCD Detector (2x1 CCDs).
Nota: this is the same for lx170hs
BINNED_PIXEL_SIZE = {1: 4.42708e-05, 2: 8.85417e-05, 3: 0.0001328125, 4: 0.0001770833, 5: 0.0002213542, 6: 0.000265625, 8: 0.0003541667, 10: 0.0004427083}
MAX_SHAPE = (1920, 3840)
__init__(pixel1=4.42708e-05, pixel2=4.42708e-05)
aliases = [’Rayonix LX170’, ‘Rayonix LX170-HS’, ‘Rayonix LX170 HS’, ‘RayonixLX170HS’]
6.9. detectors Module 191
![Page 196: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/196.jpg)
pyFAI Documentation, Release 0.15.0a0
force_pixel = True
class pyFAI.detectors.RayonixLx255(pixel1=4.42708e-05, pixel2=4.42708e-05)Bases: pyFAI.detectors.Rayonix
Rayonix lx255 2d Detector (3x1 CCDs)
Nota: this detector is also called lx255hs
BINNED_PIXEL_SIZE = {1: 4.42708e-05, 2: 8.85417e-05, 3: 0.0001328125, 4: 0.0001770833, 5: 0.0002213542, 6: 0.000265625, 8: 0.0003541667, 10: 0.0004427083}
MAX_SHAPE = (1920, 5760)
__init__(pixel1=4.42708e-05, pixel2=4.42708e-05)
aliases = [’Rayonix LX255’, ‘Rayonix LX255-HS’, ‘Rayonix LX 255HS’, ‘RayonixLX225HS’]
class pyFAI.detectors.RayonixMx170(pixel1=4.42708e-05, pixel2=4.42708e-05)Bases: pyFAI.detectors.Rayonix
Rayonix mx170 2d CCD Detector (2x2 CCDs).
Nota: this is the same for mx170hs
BINNED_PIXEL_SIZE = {1: 4.42708e-05, 2: 8.85417e-05, 3: 0.0001328125, 4: 0.0001770833, 5: 0.0002213542, 6: 0.000265625, 8: 0.0003541667, 10: 0.0004427083}
MAX_SHAPE = (3840, 3840)
__init__(pixel1=4.42708e-05, pixel2=4.42708e-05)
aliases = [’Rayonix MX170’, ‘Rayonix MX170-HS’, ‘RayonixMX170HS’, ‘Rayonix MX170 HS’]
class pyFAI.detectors.RayonixMx225(pixel1=7.3242e-05, pixel2=7.3242e-05)Bases: pyFAI.detectors.Rayonix
Rayonix mx225 2D CCD detector detector
Nota: this is the same definition for mx225he Personnal communication from M. Blum
BINNED_PIXEL_SIZE = {8: 0.000292969, 1: 3.6621e-05, 2: 7.3242e-05, 3: 0.000109971, 4: 0.000146484}
MAX_SHAPE = (6144, 6144)
__init__(pixel1=7.3242e-05, pixel2=7.3242e-05)
aliases = [’Rayonix MX225’]
force_pixel = True
class pyFAI.detectors.RayonixMx225hs(pixel1=7.8125e-05, pixel2=7.8125e-05)Bases: pyFAI.detectors.Rayonix
Rayonix mx225hs 2D CCD detector detector
Pixel size from a personnal communication from M. Blum
BINNED_PIXEL_SIZE = {1: 3.90625e-05, 2: 7.8125e-05, 3: 0.0001171875, 4: 0.00015625, 5: 0.0001953125, 6: 0.000234375, 8: 0.0003125, 10: 0.000390625}
MAX_SHAPE = (5760, 5760)
__init__(pixel1=7.8125e-05, pixel2=7.8125e-05)
aliases = [’Rayonix MX225HS’, ‘Rayonix MX225 HS’]
force_pixel = True
class pyFAI.detectors.RayonixMx300(pixel1=7.3242e-05, pixel2=7.3242e-05)Bases: pyFAI.detectors.Rayonix
Rayonix mx300 2D detector (4x4 CCDs)
Pixel size from a personnal communication from M. Blum
BINNED_PIXEL_SIZE = {8: 0.000292969, 1: 3.6621e-05, 2: 7.3242e-05, 3: 0.000109971, 4: 0.000146484}
MAX_SHAPE = (8192, 8192)
192 Chapter 6. pyFAI API
![Page 197: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/197.jpg)
pyFAI Documentation, Release 0.15.0a0
__init__(pixel1=7.3242e-05, pixel2=7.3242e-05)
aliases = [’Rayonix mx300’]
force_pixel = True
class pyFAI.detectors.RayonixMx300hs(pixel1=7.8125e-05, pixel2=7.8125e-05)Bases: pyFAI.detectors.Rayonix
Rayonix mx300hs 2D detector (4x4 CCDs)
Pixel size from a personnal communication from M. Blum
BINNED_PIXEL_SIZE = {1: 3.90625e-05, 2: 7.8125e-05, 3: 0.0001171875, 4: 0.00015625, 5: 0.0001953125, 6: 0.000234375, 8: 0.0003125, 10: 0.000390625}
MAX_SHAPE = (7680, 7680)
__init__(pixel1=7.8125e-05, pixel2=7.8125e-05)
aliases = [’Rayonix MX300HS’, ‘Rayonix MX300 HS’]
force_pixel = True
class pyFAI.detectors.RayonixMx325(pixel1=7.9346e-05, pixel2=7.9346e-05)Bases: pyFAI.detectors.Rayonix
Rayonix mx325 and mx325he 2D detector (4x4 CCD chips)
Pixel size from a personnal communication from M. Blum
BINNED_PIXEL_SIZE = {8: 0.000317383, 1: 3.9673e-05, 2: 7.9346e-05, 3: 0.000119135, 4: 0.000158691}
MAX_SHAPE = (8192, 8192)
__init__(pixel1=7.9346e-05, pixel2=7.9346e-05)
aliases = [’Rayonix MX325’]
class pyFAI.detectors.RayonixMx340hs(pixel1=8.85417e-05, pixel2=8.85417e-05)Bases: pyFAI.detectors.Rayonix
Rayonix mx340hs 2D detector (4x4 CCDs)
Pixel size from a personnal communication from M. Blum
BINNED_PIXEL_SIZE = {1: 4.42708e-05, 2: 8.85417e-05, 3: 0.0001328125, 4: 0.0001770833, 5: 0.0002213542, 6: 0.000265625, 8: 0.0003541667, 10: 0.0004427083}
MAX_SHAPE = (7680, 7680)
__init__(pixel1=8.85417e-05, pixel2=8.85417e-05)
aliases = [’Rayonix MX340HS’, ‘Rayonix MX340HS’]
force_pixel = True
class pyFAI.detectors.RayonixMx425hs(pixel1=4.42708e-05, pixel2=4.42708e-05)Bases: pyFAI.detectors.Rayonix
Rayonix mx425hs 2D CCD camera (5x5 CCD chip)
Pixel size from a personnal communication from M. Blum
BINNED_PIXEL_SIZE = {1: 4.42708e-05, 2: 8.85417e-05, 3: 0.0001328125, 4: 0.0001770833, 5: 0.0002213542, 6: 0.000265625, 8: 0.0003541667, 10: 0.0004427083}
MAX_SHAPE = (9600, 9600)
__init__(pixel1=4.42708e-05, pixel2=4.42708e-05)
aliases = [’Rayonix MX425HS’, ‘Rayonix MX425 HS’]
class pyFAI.detectors.RayonixSx165(pixel1=3.95e-05, pixel2=3.95e-05)Bases: pyFAI.detectors.Rayonix
Rayonix sx165 2d Detector also known as MAR165.
Circular detector
6.9. detectors Module 193
![Page 198: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/198.jpg)
pyFAI Documentation, Release 0.15.0a0
BINNED_PIXEL_SIZE = {8: 0.000316, 1: 3.95e-05, 2: 7.9e-05, 3: 0.000118616, 4: 0.000158}
MAX_SHAPE = (4096, 4096)
__init__(pixel1=3.95e-05, pixel2=3.95e-05)
aliases = [’MAR165’, ‘Rayonix Sx165’]
calc_mask()Circular mask
force_pixel = True
class pyFAI.detectors.RayonixSx200(pixel1=4.8e-05, pixel2=4.8e-05)Bases: pyFAI.detectors.Rayonix
Rayonix sx200 2d CCD Detector.
Pixel size are personnal communication from M. Blum.
BINNED_PIXEL_SIZE = {8: 0.000384, 1: 4.8e-05, 2: 9.6e-05, 3: 0.000144, 4: 0.000192}
MAX_SHAPE = (4096, 4096)
__init__(pixel1=4.8e-05, pixel2=4.8e-05)
aliases = [’Rayonix sx200’]
class pyFAI.detectors.RayonixSx30hs(pixel1=1.5625e-05, pixel2=1.5625e-05)Bases: pyFAI.detectors.Rayonix
Rayonix sx30hs 2D CCD camera (1 CCD chip)
Pixel size from a personnal communication from M. Blum
BINNED_PIXEL_SIZE = {1: 1.5625e-05, 2: 3.125e-05, 3: 4.6875e-05, 4: 6.25e-05, 5: 7.8125e-05, 6: 9.375e-05, 8: 0.000125, 10: 0.00015625}
MAX_SHAPE = (1920, 1920)
__init__(pixel1=1.5625e-05, pixel2=1.5625e-05)
aliases = [’Rayonix SX30HS’, ‘Rayonix SX30 HS’]
class pyFAI.detectors.RayonixSx85hs(pixel1=4.42708e-05, pixel2=4.42708e-05)Bases: pyFAI.detectors.Rayonix
Rayonix sx85hs 2D CCD camera (1 CCD chip)
Pixel size from a personnal communication from M. Blum
BINNED_PIXEL_SIZE = {1: 4.42708e-05, 2: 8.85417e-05, 3: 0.0001328125, 4: 0.0001770833, 5: 0.0002213542, 6: 0.000265625, 8: 0.0003541667, 10: 0.0004427083}
MAX_SHAPE = (1920, 1920)
__init__(pixel1=4.42708e-05, pixel2=4.42708e-05)
aliases = [’Rayonix SX85HS’, ‘Rayonix SX85 HS’]
class pyFAI.detectors.Titan(pixel1=6e-05, pixel2=6e-05)Bases: pyFAI.detectors.Detector
Titan CCD detector from Agilent. Mask not handled
MAX_SHAPE = (2048, 2048)
__init__(pixel1=6e-05, pixel2=6e-05)
aliases = [’Titan 2k x 2k’, ‘OXD Titan’, ‘Agilent Titan’]
force_pixel = True
uniform_pixel = True
194 Chapter 6. pyFAI API
![Page 199: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/199.jpg)
pyFAI Documentation, Release 0.15.0a0
class pyFAI.detectors.Xpad_flat(pixel1=0.00013, pixel2=0.00013, max_shape=None, mod-ule_size=None)
Bases: pyFAI.detectors.ImXPadS10
Xpad detector: generic description for ImXPad detector with 8x7modules
BORDER_PIXEL_SIZE_RELATIVE = 2.5
IS_CONTIGUOUS = False
MAX_SHAPE = (960, 560)
MODULE_GAP = (0.00357, 0)
MODULE_SIZE = (120, 80)
PIXEL_SIZE = (0.00013, 0.00013)
__init__(pixel1=0.00013, pixel2=0.00013, max_shape=None, module_size=None)
aliases = [’Xpad S540 flat’, ‘d5’]
calc_cartesian_positions(d1=None, d2=None, center=True, use_cython=True)Calculate the position of each pixel center in cartesian coordinate and in meter of a couple of coordi-nates. The half pixel offset is taken into account here !!! Adapted to Nexus detector definition
Parameters
• d1 (ndarray (1D or 2D)) – the Y pixel positions (slow dimension)
• d2 (ndarray (1D or 2D)) – the X pixel positions (fast dimension)
• center – retrieve the coordinate of the center of the pixel
• use_cython – set to False to test Numpy implementation
Returns position in meter of the center of each pixels.
Return type ndarray
d1 and d2 must have the same shape, returned array will have the same shape.
calc_mask()Returns a generic mask for Xpad detectors... discards the first line and raw form all modules: thoseare 2.5x bigger and often mis - behaving
calc_pixels_edges()Calculate the position of the pixel edges, specific to the S540, d5 detector
force_pixel = True
get_pixel_corners()Calculate the position of the corner of the pixels
Returns 4D array containing: pixel index (slow dimension) pixel index (fast dimension)corner index (A, B, C or D), triangles or hexagons can be handled the same way vertexposition (z,y,x)
uniform_pixel = False
spline Module
This is piece of software aims at manipulating spline files describing for geometric corrections of the 2D detectorsusing cubic-spline.
Mainly used at ESRF with FReLoN CCD camera.
6.10. spline Module 195
![Page 200: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/200.jpg)
pyFAI Documentation, Release 0.15.0a0
class pyFAI.spline.Spline(filename=None)Bases: object
This class is a python representation of the spline file
Those file represent cubic splines for 2D detector distortions and makes heavy use of fit-pack (dierckx in netlib) — A Python-C wrapper to FITPACK (by P. Dierckx). FITPACKis a collection of FORTRAN programs for curve and surface fitting with splines and tensorproduct splines. See _http://www.cs.kuleuven.ac.be/cwis/research/nalag/research/topics/fitpack.html or_http://www.netlib.org/dierckx/index.html
__init__(filename=None)This is the constructor of the Spline class.
Parameters filename (str) – name of the ascii file containing the spline
array2spline(smoothing=1000, timing=False)Calculates the spline coefficients from the displacements matrix using fitpack.
Parameters
• smoothing (float) – the greater the smoothing, the fewer the number of knotsremaining
• timing (bool) – print the profiling of the calculation
bin(binning=None)Performs the binning of a spline (same camera with different binning)
Parameters binning – binning factor as integer or 2-tuple of integers
Type int or (int, int)
comparison(ref, verbose=False)Compares the current spline distortion with a reference
Parameters
• ref (Spline instance) – another spline file
• verbose (bool) – print or not pylab plots
Returns True or False depending if the splines are the same or not
Return type bool
correct(pos)
fliplr()Flip the spline :return: new spline object
fliplrud()Flip the spline left-right and up-down :return: new spline object
flipud()Flip the spline up-down :return: new spline object
getPixelSize()Return the size of the pixel from as a 2-tuple of floats expressed in meters.
Returns the size of the pixel from a 2D detector
Return type 2-tuple of floats expressed in meter.
read(filename)read an ascii spline file from file
Parameters filename (str) – file containing the cubic spline distortion file
setPixelSize(pixelSize)Sets the size of the pixel from a 2-tuple of floats expressed in meters.
196 Chapter 6. pyFAI API
![Page 201: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/201.jpg)
pyFAI Documentation, Release 0.15.0a0
Param pixel size in meter
spline2array(timing=False)Calculates the displacement matrix using fitpack bisplev(x, y, tck, dx = 0, dy = 0)
Parameters timing (bool) – profile the calculation or not
Returns Nothing !
Return type float or ndarray
Evaluate a bivariate B-spline and its derivatives. Return a rank-2 array of spline function values (orspline derivative values) at points given by the cross-product of the rank-1 arrays x and y. In specialcases, return an array or just a float if either x or y or both are floats.
splineFuncX(x, y, list_of_points=False)Calculates the displacement matrix using fitpack for the X direction on the given grid.
Parameters
• x (ndarray) – points of the grid in the x direction
• y (ndarray) – points of the grid in the y direction
• list_of_points – if true, consider the zip(x,y) instead of the of the square array
Returns displacement matrix for the X direction
Return type ndarray
splineFuncY(x, y, list_of_points=False)calculates the displacement matrix using fitpack for the Y direction
Parameters
• x (ndarray) – points in the x direction
• y (ndarray) – points in the y direction
• list_of_points – if true, consider the zip(x,y) instead of the of the square array
Returns displacement matrix for the Y direction
Return type ndarray
tilt(center=(0.0, 0.0), tiltAngle=0.0, tiltPlanRot=0.0, distanceSampleDetector=1.0, tim-ing=False)
The tilt method apply a virtual tilt on the detector, the point of tilt is given by the center
Parameters
• center (2-tuple of floats) – position of the point of tilt, this point will notbe moved.
• tiltAngle (float in the range [-90:+90] degrees) – the value ofthe tilt in degrees
• tiltPlanRot (Float in the range [-180:180]) – the rotation of the tiltplan with the Ox axis (0 deg for y axis invariant, 90 deg for x axis invariant)
• distanceSampleDetector (float) – the distance from sample to detector inmeter (along the beam, so distance from sample to center)
Returns tilted Spline instance
Return type Spline
write(filename)save the cubic spline in an ascii file usable with Fit2D or SPD
Parameters filename (str) – name of the file containing the cubic spline distortion file
6.10. spline Module 197
![Page 202: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/202.jpg)
pyFAI Documentation, Release 0.15.0a0
writeEDF(basename)save the distortion matrices into a couple of files called basename-x.edf and basename-y.edf
Parameters basename (str) – base of the name used to save the data
zeros(xmin=0.0, ymin=0.0, xmax=2048.0, ymax=2048.0, pixSize=None)Defines a spline file with no ( zero ) displacement.
Parameters
• xmin (float) – minimum coordinate in x, usually zero
• xmax (float) – maximum coordinate in x (+1) usually 2048
• ymin (float) – minimum coordinate in y, usually zero
• ymax (float) – maximum coordinate y (+1) usually 2048
• pixSize (float) – size of the pixel
zeros_like(other)Defines a spline file with no ( zero ) displacement with the same shape as the other one given.
Parameters other (Spline instance) – another Spline instance
pyFAI.spline.main()Some tests ....
io Module
Module for “high-performance” writing in either 1D with Ascii , or 2D with FabIO or even nD with n varyingfrom 2 to 4 using HDF5
Stand-alone module which tries to offer interface to HDF5 via H5Py and capabilities to write EDF or other formatsusing fabio.
Can be imported without h5py but then limited to fabio & ascii formats.
TODO:
• Add monitor to HDF5
class pyFAI.io.AsciiWriter(filename=None, prefix=’fai_’, extension=’.dat’)Bases: pyFAI.io.Writer
Ascii file writer (.xy or .dat)
__init__(filename=None, prefix=’fai_’, extension=’.dat’)
init(fai_cfg=None, lima_cfg=None)Creates the directory that will host the output file(s)
write(data, index=0)
class pyFAI.io.DefaultAiWriter(filename, engine=None)Bases: pyFAI.io.Writer
__init__(filename, engine=None)Constructor of the historical writer of azimuthalIntegrator.
Parameters
• filename – name of the output file
• ai – integrator, should provide make_headers method.
close()
flush()
198 Chapter 6. pyFAI API
![Page 203: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/203.jpg)
pyFAI Documentation, Release 0.15.0a0
make_headers(hdr=’#’, has_mask=None, has_dark=None, has_flat=None, polariza-tion_factor=None, normalization_factor=None, metadata=None)
Parameters
• hdr (str) – string used as comment in the header
• has_dark (bool) – save the darks filenames (default: no)
• has_flat (bool) – save the flat filenames (default: no)
• polarization_factor (float) – the polarization factor
Returns the header
Return type str
save1D(filename, dim1, I, error=None, dim1_unit=‘2th_deg’, has_mask=None, has_dark=False,has_flat=False, polarization_factor=None, normalization_factor=None, metadata=None)
This method save the result of a 1D integration as ASCII file.
Parameters
• filename (str) – the filename used to save the 1D integration
• dim1 (numpy.ndarray) – the x coordinates of the integrated curve
• I (numpy.mdarray) – The integrated intensity
• error (numpy.ndarray or None) – the error bar for each intensity
• dim1_unit (pyFAI.units.Unit) – the unit of the dim1 array
• has_dark (bool) – save the darks filenames (default: no)
• has_flat (bool) – save the flat filenames (default: no)
• polarization_factor (float, None) – the polarization factor
• normalization_factor (float, None) – the monitor value
• metadata – JSON serializable dictionary containing the metadata
This method save the result of a 1D integration.
save2D(filename, I, dim1, dim2, error=None, dim1_unit=‘2th_deg’, has_dark=False,has_flat=False, polarization_factor=None, normalization_factor=None, metadata=None)
This method save the result of a 2D integration.
Parameters
• filename (str) – the filename used to save the 2D histogram
• dim1 (numpy.ndarray) – the 1st coordinates of the histogram
• dim1 – the 2nd coordinates of the histogram
• I (numpy.mdarray) – The integrated intensity
• error (numpy.ndarray or None) – the error bar for each intensity
• dim1_unit (pyFAI.units.Unit) – the unit of the dim1 array
• has_dark (bool) – save the darks filenames (default: no)
• has_flat (bool) – save the flat filenames (default: no)
• polarization_factor (float, None) – the polarization factor
• normalization_factor (float, None) – the monitor value
• metadata – JSON serializable dictionary containing the metadata
set_filename(filename)Define the filename while will be used
6.11. io Module 199
![Page 204: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/204.jpg)
pyFAI Documentation, Release 0.15.0a0
write(data)Minimalistic method to limit the overhead.
Parameters data – array with intensities or tuple (2th,I) or (I,2th,chi) :type data: Inte-grate1dResult, Integrate2dResult
class pyFAI.io.FabioWriter(filename=None)Bases: pyFAI.io.Writer
Image file writer based on FabIO
TODO !!!
__init__(filename=None)
init(fai_cfg=None, lima_cfg=None)Creates the directory that will host the output file(s)
write(data, index=0)
class pyFAI.io.HDF5Writer(filename, hpath=’data’, fast_scan_width=None)Bases: pyFAI.io.Writer
Class allowing to write HDF5 Files.
CONFIG = ‘pyFAI’
DATASET_NAME = ‘data’
__init__(filename, hpath=’data’, fast_scan_width=None)Constructor of an HDF5 writer:
Parameters
• filename – name of the file
• hpath – name of the group: it will contain data (2-4D dataset), [tth|q|r] and pyFAI,group containing the configuration
• fast_scan_width – set it to define the width of
close()
flush(radial=None, azimuthal=None)Update some data like axis units and so on.
Parameters
• radial – position in radial direction
• azimuthal – position in azimuthal direction
init(fai_cfg=None, lima_cfg=None)Initializes the HDF5 file for writing :param fai_cfg: the configuration of the worker as a dictionary
write(data, index=0)Minimalistic method to limit the overhead. :param data: array with intensities or tuple (2th,I) or(I,2th,chi)
class pyFAI.io.Nexus(filename, mode=’r’)Bases: object
Writer class to handle Nexus/HDF5 data
Manages:
•entry
–pyFAI-subentry
*detector
TODO: make it thread-safe !!!
200 Chapter 6. pyFAI API
![Page 205: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/205.jpg)
pyFAI Documentation, Release 0.15.0a0
__init__(filename, mode=’r’)Constructor
Parameters
• filename – name of the hdf5 file containing the nexus
• mode – can be r or a
close()close the filename and update all entries
deep_copy(name, obj, where=’/’, toplevel=None, excluded=None, overwrite=False)perform a deep copy: create a “name” entry in self containing a copy of the object
Parameters
• where – path to the toplevel object (i.e. root)
• toplevel – firectly the top level Group
• excluded – list of keys to be excluded
• overwrite – replace content if already existing
find_detector(all=False)Tries to find a detector within a NeXus file, takes the first compatible detector
Parameters all – return all detectors found as a list
classmethod get_attr(dset, name, default=None)Return the attribute of the dataset
Handles the ascii -> unicode issue in python3 #275
Parameters
• dset – a HDF5 dataset (or a group)
• name – name of the attribute
• default – default value to be returned
Returns attribute value decoded in python3 or default
get_class(grp, class_type=’NXcollection’)return all sub-groups of the given type within a group
Parameters
• grp – HDF5 group
• class_type – name of the NeXus class
get_data(grp, class_type=’NXdata’)return all dataset of the the NeXus class NXdata
Parameters
• grp – HDF5 group
• class_type – name of the NeXus class
get_entries()retrieves all entry sorted the latest first.
Returns list of HDF5 groups
get_entry(name)Retrieves an entry from its name
Parameters name – name of the entry to retrieve
Returns HDF5 group of NXclass == NXentry
6.11. io Module 201
![Page 206: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/206.jpg)
pyFAI Documentation, Release 0.15.0a0
new_class(grp, name, class_type=’NXcollection’)create a new sub-group with type class_type :param grp: parent group :param name: name of thesub-group :param class_type: NeXus class name :return: subgroup created
new_detector(name=’detector’, entry=’entry’, subentry=’pyFAI’)Create a new entry/pyFAI/Detector
Parameters
• detector – name of the detector
• entry – name of the entry
• subentry – all pyFAI description of detectors should be in a pyFAI sub-entry
new_entry(entry=’entry’, program_name=’pyFAI’, title=’description of experiment’,force_time=None, force_name=False)
Create a new entry
Parameters
• entry – name of the entry
• program_name – value of the field as string
• title – value of the field as string
• force_time – enforce the start_time (as string!)
• force_name – force the entry name as such, without numerical suffix.
Returns the corresponding HDF5 group
new_instrument(entry=’entry’, instrument_name=’id00’)Create an instrument in an entry or create both the entry and the instrument if
class pyFAI.io.Writer(filename=None, extension=None)Bases: object
Abstract class for writers.
CONFIG_ITEMS = [’filename’, ‘dirname’, ‘extension’, ‘subdir’, ‘hpath’]
__init__(filename=None, extension=None)Constructor of the class
flush(*arg, **kwarg)To be implemented
init(fai_cfg=None, lima_cfg=None)Creates the directory that will host the output file(s) :param fai_cfg: configuration for worker :paramlima_cfg: configuration for acquisition
setJsonConfig(json_config=None)Sets the JSON configuration
write(data)To be implemented
pyFAI.io.from_isotime(text, use_tz=False)
Parameters text – string representing the time is iso format
pyFAI.io.get_isotime(forceTime=None)
Parameters forceTime (float) – enforce a given time (current by default)
Returns the current time as an ISO8601 string
Return type string
pyFAI.io.is_hdf5(filename)Check if a file is actually a HDF5 file
202 Chapter 6. pyFAI API
![Page 207: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/207.jpg)
pyFAI Documentation, Release 0.15.0a0
Parameters filename – this file has better to exist
calibration Module
control_points Module
ControlPoints: a set of control points associated with a calibration image
PointGroup: a group of points
class pyFAI.control_points.ControlPoints(filename=None, calibrant=None, wave-length=None)
Bases: object
This class contains a set of control points with (optionally) their ring number hence d-spacing and diffraction2Theta angle ...
__init__(filename=None, calibrant=None, wavelength=None)
append(points, ring=None, annotate=None, plot=None)Append a group of points to a given ring
Parameters
• point – list of points
• ring – ring number
• annotate – matplotlib.annotate reference
• plot – matplotlib.plot reference
Returns PointGroup instance
append_2theta_deg(points, angle=None, ring=None)Append a group of points to a given ring
Parameters
• point – list of points
• angle – 2-theta angle in degrees
Param ring: ring number
check()check internal consistency of the class, disabled for now
dSpacing
get(ring=None, lbl=None)Retireves the last group of points for a given ring (by default the last)
Parameters
• ring – index of ring to search for
• lbl – label of the group to retrieve
getList()Retrieve the list of control points suitable for geometry refinement with ring number
getList2theta()Retrieve the list of control points suitable for geometry refinement
getListRing()Retrieve the list of control points suitable for geometry refinement with ring number
6.12. calibration Module 203
![Page 208: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/208.jpg)
pyFAI Documentation, Release 0.15.0a0
getWeightedList(image)Retrieve the list of control points suitable for geometry refinement with ring number and intensities:param image: :return: a (x,4) array with pos0, pos1, ring nr and intensity
#TODO: refine the value of the intensity using 2nd order polynomia
get_dSpacing()
get_labels()Retieve the list of labels
Returns list of labels as string
get_wavelength()
load(filename)load all control points from a file
pop(ring=None, lbl=None)Remove the set of points, either from its code or from a given ring (by default the last)
Parameters
• ring – index of ring of which remove the last group
• lbl – code of the ring to remove
readRingNrFromKeyboard()Ask the ring number values for the given points
reset()remove all stored values and resets them to default
save(filename)Save a set of control points to a file :param filename: name of the file :return: None
setWavelength_change2th(value=None)
setWavelength_changeDs(value=None)This is probably not a good idea, but who knows !
set_dSpacing(lst)
set_wavelength(value=None)
wavelength
class pyFAI.control_points.PointGroup(points=None, ring=None, annotate=None,plot=None, force_label=None)
Bases: object
Class contains a group of points ... They all belong to the same Debye-Scherrer ring
__init__(points=None, ring=None, annotate=None, plot=None, force_label=None)Constructor
Parameters
• points – list of points
• ring – ring number
• annotate – reference to the matplotlib annotate output
• plot – reference to the matplotlib plot
• force_label – allows to enforce the label
codeNumerical value for the label: mainly for sorting
classmethod get_label()return the next label
204 Chapter 6. pyFAI API
![Page 209: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/209.jpg)
pyFAI Documentation, Release 0.15.0a0
get_ring()
label
last_label = 0
classmethod reset_label()reset intenal counter
ring
classmethod set_label(label)update the internal counter if needed
set_ring(value)
peak_picker Module
Semi-graphical tool for peak-picking and extracting visually control points from an image with Debye-Schererrings
class pyFAI.peak_picker.ControlPoints(filename=None, calibrant=None, wave-length=None)
Bases: object
This class contains a set of control points with (optionally) their ring number hence d-spacing and diffraction2Theta angle ...
__init__(filename=None, calibrant=None, wavelength=None)
append(points, ring=None, annotate=None, plot=None)Append a group of points to a given ring
Parameters
• point – list of points
• ring – ring number
• annotate – matplotlib.annotate reference
• plot – matplotlib.plot reference
Returns PointGroup instance
append_2theta_deg(points, angle=None, ring=None)Append a group of points to a given ring
Parameters
• point – list of points
• angle – 2-theta angle in degrees
Param ring: ring number
check()check internal consistency of the class, disabled for now
dSpacing
get(ring=None, lbl=None)Retireves the last group of points for a given ring (by default the last)
Parameters
• ring – index of ring to search for
• lbl – label of the group to retrieve
6.14. peak_picker Module 205
![Page 210: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/210.jpg)
pyFAI Documentation, Release 0.15.0a0
getList()Retrieve the list of control points suitable for geometry refinement with ring number
getList2theta()Retrieve the list of control points suitable for geometry refinement
getListRing()Retrieve the list of control points suitable for geometry refinement with ring number
getWeightedList(image)Retrieve the list of control points suitable for geometry refinement with ring number and intensities:param image: :return: a (x,4) array with pos0, pos1, ring nr and intensity
#TODO: refine the value of the intensity using 2nd order polynomia
get_dSpacing()
get_labels()Retieve the list of labels
Returns list of labels as string
get_wavelength()
load(filename)load all control points from a file
pop(ring=None, lbl=None)Remove the set of points, either from its code or from a given ring (by default the last)
Parameters
• ring – index of ring of which remove the last group
• lbl – code of the ring to remove
readRingNrFromKeyboard()Ask the ring number values for the given points
reset()remove all stored values and resets them to default
save(filename)Save a set of control points to a file :param filename: name of the file :return: None
setWavelength_change2th(value=None)
setWavelength_changeDs(value=None)This is probably not a good idea, but who knows !
set_dSpacing(lst)
set_wavelength(value=None)
wavelength
class pyFAI.peak_picker.PeakPicker(data, reconst=False, mask=None, pointfile=None,calibrant=None, wavelength=None, detector=None,method=’massif’)
Bases: object
This class is in charge of peak picking, i.e. find bragg spots in the image Two methods can be used : massifor blob
VALID_METHODS = [’massif’, ‘blob’, ‘watershed’]
__init__(data, reconst=False, mask=None, pointfile=None, calibrant=None, wavelength=None,detector=None, method=’massif’)
Parameters
• data – input image as numpy array
206 Chapter 6. pyFAI API
![Page 211: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/211.jpg)
pyFAI Documentation, Release 0.15.0a0
• reconst – shall masked part or negative values be reconstructed (wipe out problemswith pilatus gaps)
• mask – area in which keypoints will not be considered as valid
• pointfile –
closeGUI()
contour(data, cmap=’autumn’, linewidths=2, linestyles=’dashed’)Overlay a contour-plot
Parameters data – 2darray with the 2theta values in radians...
display_points(minIndex=0, reset=False)display all points and their ring annotations :param minIndex: ring index to start with :param reset:remove all point before re-displaying them
finish(filename=None, callback=None)Ask the ring number for the given points
Parameters filename – file with the point coordinates saved
gui(log=False, maximize=False, pick=True)
Parameters log – show z in log scale
help = [’Please select rings on the diffraction image. In parenthesis, some modified shortcuts for single button mouse (Apple):’, ‘ * Right-click (click+n): try an auto find for a ring’, ‘ * Right-click + Ctrl (click+b): create new group with one point’, ‘ * Right-click + Shift (click+v): add one point to current group’, ‘ * Right-click + m (click+m): find more points for current group’, ‘ * Center-click or (click+d): erase current group’, ‘ * Center-click + 1 or (click+1): erase closest point from current group’]
init(method, sync=True)Unified initializer
load(filename)load a filename and plot data on the screen (if GUI)
massif_contour(data)Overlays a mask over a diffraction image
Parameters data – mask to be overlaid
on_minus_pts_clicked(*args)callback function
on_option_clicked(*args)callback function
on_plus_pts_clicked(*args)callback function
on_refine_clicked(*args)callback function
onclick(event)Called when a mouse is clicked
peaks_from_area(**kwargs)Return the list of peaks within an area
Parameters
• mask – 2d array with mask.
• Imin – minimum of intensity above the background to keep the point
• keep – maximum number of points to keep
• method – enforce the use of detection using “massif” or “blob” or “watershed”
• ring – ring number to which assign the points
• dmin – minimum distance between two peaks (in pixels)
• seed – good starting points.
6.14. peak_picker Module 207
![Page 212: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/212.jpg)
pyFAI Documentation, Release 0.15.0a0
Returns list of peaks [y,x], [y,x], ...]
remove_grp(lbl)remove a group of points
Parameters lbl – label of the group of points
reset()Reset control point and graph (if needed)
sync_init()
class pyFAI.peak_picker.PointGroup(points=None, ring=None, annotate=None, plot=None,force_label=None)
Bases: object
Class contains a group of points ... They all belong to the same Debye-Scherrer ring
__init__(points=None, ring=None, annotate=None, plot=None, force_label=None)Constructor
Parameters
• points – list of points
• ring – ring number
• annotate – reference to the matplotlib annotate output
• plot – reference to the matplotlib plot
• force_label – allows to enforce the label
codeNumerical value for the label: mainly for sorting
classmethod get_label()return the next label
get_ring()
label
last_label = 0
classmethod reset_label()reset intenal counter
ring
classmethod set_label(label)update the internal counter if needed
set_ring(value)
massif Module
class pyFAI.massif.Massif(data=None)Bases: object
A massif is defined as an area around a peak, it is used to find neighboring peaks
TARGET_SIZE = 1024
__init__(data=None)
calculate_massif(x)defines a map of the massif around x and returns the mask
delValleySize()
208 Chapter 6. pyFAI API
![Page 213: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/213.jpg)
pyFAI Documentation, Release 0.15.0a0
find_peaks(x, nmax=200, annotate=None, massif_contour=None, stdout=<open file ‘<stdout>’,mode ‘w’>)
All in one function that finds a maximum from the given seed (x) then calculates the region extensionand extract position of the neighboring peaks. :param x: coordinates of the peak, seed for the calcula-tion :type x: tuple of integer :param nmax: maximum number of peak per region :param annotate: callback method taking number of points + coordinate as input. :param massif_contour: callback to showthe contour of a massif with the given index. :param stdout: this is the file where output is written bydefault. :return: list of peaks
getBinnedData()
Returns binned data
getBluredData()
Returns a blurred image
getLabeledMassif(pattern=None)
Returns an image composed of int with a different value for each massif
getMedianData()
Returns a spacial median filtered image
getValleySize()
initValleySize()
nearest_peak(x)
Parameters x – coordinates of the peak
Returns the coordinates of the nearest peak
peaks_from_area(mask, Imin=None, keep=1000, dmin=0.0, seed=None, **kwarg)Return the list of peaks within an area
Parameters
• mask – 2d array with mask.
• Imin – minimum of intensity above the background to keep the point
• keep – maximum number of points to keep
• kwarg – ignored parameters
• dmin – minimum distance to another peak
• seed – list of good guesses to start with
Returns list of peaks [y,x], [y,x], ...]
setValleySize(size)
valley_sizeDefines the minimum distance between two massifs
blob_detection Module
class pyFAI.blob_detection.BlobDetection(img, cur_sigma=0.25, init_sigma=0.5,dest_sigma=1, scale_per_octave=2,mask=None)
Bases: object
Performs a blob detection: http://en.wikipedia.org/wiki/Blob_detection using a Difference of Gaussian +Pyramid of Gaussians
6.16. blob_detection Module 209
![Page 214: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/214.jpg)
pyFAI Documentation, Release 0.15.0a0
__init__(img, cur_sigma=0.25, init_sigma=0.5, dest_sigma=1, scale_per_octave=2,mask=None)
Performs a blob detection: http://en.wikipedia.org/wiki/Blob_detection using a Difference of Gaussian+ Pyramid of Gaussians
Parameters
• img – input image
• cur_sigma – estimated smoothing of the input image. 0.25 correspond to no inter-action between pixels.
• init_sigma – start searching at this scale (sigma=0.5: 10% interaction with firstneighbor)
• dest_sigma – sigma at which the resolution is lowered (change of octave)
• scale_per_octave – Number of scale to be performed per octave
• mask – mask where pixel are not valid
direction()Perform and plot the two main directions of the peaks, considering their previously calculated scale,by calculating the Hessian at different sizes as the combination of gaussians and their first and secondderivatives
nearest_peak(p, refine=True, Imin=None)Return the nearest peak from a position
Parameters
• p – input position (y,x) 2-tuple of float
• refine – shall the position be refined on the raw data
• Imin – minimum of intensity above the background
peaks_from_area(mask, keep=None, refine=True, Imin=None, dmin=0.0, **kwargs)Return the list of peaks within an area
Parameters
• mask – 2d array with mask.
• refine – shall the position be refined on the raw data
• Imin – minimum of intensity above the background
• kwarg – ignored parameters
Returns list of peaks [y,x], [y,x], ...]
process(max_octave=None)Perform the keypoint extraction for max_octave cycles or until all octaves have been processed. :parammax_octave: number of octave to process
refine_Hessian(kpx, kpy, kps)Refine the keypoint location based on a 3 point derivative, and delete non-coherent keypoints.
Parameters
• kpx – x_pos of keypoint
• kpy – y_pos of keypoint
• kps – s_pos of keypoint
Returns arrays of corrected coordinates of keypoints, values and locations of keypoints
refine_Hessian_SG(kpx, kpy, kps)Savitzky Golay algorithm to check if a point is really the maximum :param kpx: x_pos of keypoint:param kpy: y_pos of keypoint :param kps: s_pos of keypoint :return: array of corrected keypoints
210 Chapter 6. pyFAI API
![Page 215: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/215.jpg)
pyFAI Documentation, Release 0.15.0a0
refinement()
show_neighboor()
show_stats()Shows a window with the repartition of keypoint in function of scale/intensity
tresh = 0.6
pyFAI.blob_detection.image_test()
pyFAI.blob_detection.local_max(dogs, mask=None, n_5=True)
Parameters
• dogs – 3d array with (sigma,y,x) containing difference of gaussians
• mask – mask out keypoint next to the mask (or inside the mask)
• n_5 – look for a larger neighborhood
pyFAI.blob_detection.make_gaussian(im, sigma, xc, yc)
calibrant Module
Calibrant
A module containing classical calibrant and also tools to generate d-spacing.
Interesting formula: http://geoweb3.princeton.edu/research/MineralPhy/xtalgeometry.pdf
pyFAI.calibrant.CALIBRANT_FACTORY = Calibrants available: Ni, CrOx, NaCl, Si_SRM640e, Si_SRM640d, Si_SRM640a, Si_SRM640c, Si_SRM640b, Cr2O3, TiO2, Si_SRM640, CuO, PBBA, alpha_Al2O3, mock, quartz, C14H30O, cristobaltite, Si, LaB6, CeO2, LaB6_SRM660a, LaB6_SRM660b, LaB6_SRM660c, AgBh, ZnO, Al, AuDefault calibration factory provided by the library.
class pyFAI.calibrant.Calibrant(filename=None, dSpacing=None, wavelength=None)Bases: object
A calibrant is a reference compound where the d-spacing (interplanar distances) are known. They areexpressed in Angstrom (in the file)
__init__(filename=None, dSpacing=None, wavelength=None)
append_2th(value)
append_dSpacing(value)
dSpacing
fake_calibration_image(ai, shape=None, Imax=1.0, U=0, V=0, W=0.0001)Generates a fake calibration image from an azimuthal integrator
Parameters
• ai – azimuthal integrator
• Imax – maximum intensity of rings
• V, W (U,) – width of the peak from Caglioti’s law (FWHM^2 = Utan(th)^2 +Vtan(th) + W)
get_2th()
get_2th_index(angle)return the index in the 2theta angle index
get_dSpacing()
get_wavelength()
load_file(filename=None)
6.17. calibrant Module 211
![Page 216: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/216.jpg)
pyFAI Documentation, Release 0.15.0a0
save_dSpacing(filename=None)save the d-spacing to a file
setWavelength_change2th(value=None)
setWavelength_changeDs(value=None)This is probably not a good idea, but who knows !
set_dSpacing(lst)
set_wavelength(value=None)
wavelength
class pyFAI.calibrant.CalibrantFactory(basedir=None)Bases: object
Behaves like a dict but is actually a factory:
Each time one retrieves an object it is a new geniune new calibrant (unmodified)
__init__(basedir=None)Constructor
Parameters basedir – directory name where to search for the calibrants
get(what, notfound=None)
has_key(k)
items()
keys()
values()
class pyFAI.calibrant.Cell(a=1, b=1, c=1, alpha=90, beta=90, gamma=90, lattice=’triclinic’,lattice_type=’P’)
Bases: object
This is a cell object, able to calculate the volume and d-spacing according to formula from:
http://geoweb3.princeton.edu/research/MineralPhy/xtalgeometry.pdf
__init__(a=1, b=1, c=1, alpha=90, beta=90, gamma=90, lattice=’triclinic’, lattice_type=’P’)Constructor of the Cell class:
Crystalographic units are Angstrom for distances and degrees for angles !
Parameters
• a,b,c – unit cell length in Angstrom
• beta, gamma (alpha,) – unit cell angle in degrees
• lattice – “cubic”, “tetragonal”, “hexagonal”, “rhombohedral”, “orthorhombic”,“monoclinic”, “triclinic”
• lattice_type – P, I, F, C or R
classmethod cubic(a, lattice_type=’P’)Factory for cubic lattices
Parameters a – unit cell length
d(hkl)Calculate the actual d-spacing for a 3-tuple of integer representing a family of Miller plans
Parameters hkl – 3-tuple of integers
Returns the inter-planar distance
212 Chapter 6. pyFAI API
![Page 217: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/217.jpg)
pyFAI Documentation, Release 0.15.0a0
d_spacing(dmin=1.0)Calculate all d-spacing down to dmin
applies selection rules
Parameters dmin – minimum value of spacing requested
Returns dict d-spacing as string, list of tuple with Miller indices preceded with the numeri-cal value
classmethod diamond(a)Factory for Diamond type FCC like Si and Ge
Parameters a – unit cell length
get_type()
classmethod hexagonal(a, c, lattice_type=’P’)Factory for hexagonal lattices
Parameters
• a – unit cell length
• c – unit cell length
lattices = [’cubic’, ‘tetragonal’, ‘hexagonal’, ‘rhombohedral’, ‘orthorhombic’, ‘monoclinic’, ‘triclinic’]
classmethod monoclinic(a, b, c, beta, lattice_type=’P’)Factory for hexagonal lattices
Parameters
• a – unit cell length
• b – unit cell length
• c – unit cell length
• beta – unit cell angle
classmethod orthorhombic(a, b, c, lattice_type=’P’)Factory for orthorhombic lattices
Parameters
• a – unit cell length
• b – unit cell length
• c – unit cell length
classmethod rhombohedral(a, alpha, lattice_type=’P’)Factory for hexagonal lattices
Parameters
• a – unit cell length
• alpha – unit cell angle
save(name, long_name=None, doi=None, dmin=1.0, dest_dir=None)Save informations about the cell in a d-spacing file, usable as Calibrant
Parameters
• name – name of the calibrant
• doi – reference of the publication used to parametrize the cell
• dmin – minimal d-spacing
• dest_dir – name of the directory where to save the result
6.17. calibrant Module 213
![Page 218: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/218.jpg)
pyFAI Documentation, Release 0.15.0a0
selection_rules = Nonecontains a list of functions returning True(allowed)/False(forbiden)/None(unknown)
set_type(lattice_type)
classmethod tetragonal(a, c, lattice_type=’P’)Factory for tetragonal lattices
Parameters
• a – unit cell length
• c – unit cell length
type
types = {‘I’: ‘Body centered’, ‘P’: ‘Primitive’, ‘C’: ‘Side centered’, ‘R’: ‘Rhombohedral’, ‘F’: ‘Face centered’}
volume
pyFAI.calibrant.get_calibrant(calibrant_name)Returns a new instance of the calibrant by it’s name.
Parameters calibrant_name (str) – Name of the calibrant
pyFAI.calibrant.names()Returns the list of registred calibrant names.
Return type str
distortion Module
class pyFAI.distortion.Distortion(detector=’detector’, shape=None, resize=False, empty=0,mask=None, method=’CSR’, device=None, workgroup=8)
Bases: object
This class applies a distortion correction on an image.
New version compatible both with CSR and LUT...
__init__(detector=’detector’, shape=None, resize=False, empty=0, mask=None, method=’CSR’,device=None, workgroup=8)
Parameters
• detector – detector instance or detector name
• shape – shape of the output image
• resize – allow the output shape to be different from the input shape
• empty – value to be given for empty bins
• method – “lut” or “csr”, the former is faster
• device – Name of the device: None for OpenMP, “cpu” or “gpu” or the id of theOpenCL device a 2-tuple of integer
• workgroup – workgroup size for CSR on OpenCL
calc_LUT(use_common=True)Calculate the Look-up table
Returns look up table either in CSR or LUT format depending on serl.method
calc_init()Initialize all arrays
calc_pos(use_cython=True)Calculate the pixel boundary position on the regular grid
214 Chapter 6. pyFAI API
![Page 219: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/219.jpg)
pyFAI Documentation, Release 0.15.0a0
Returns pixel corner positions (in pixel units) on the regular grid
Return type ndarray of shape (nrow, ncol, 4, 2)
calc_size(use_cython=True)Calculate the number of pixels falling into every single bin and
Returns max of pixel falling into a single bin
Considering the “half-CCD” spline from ID11 which describes a (1025,2048) detector, the physicallocation of pixels should go from: [-17.48634 : 1027.0543, -22.768829 : 2028.3689] We chose todiscard pixels falling outside the [0:1025,0:2048] range with a lose of intensity
correct(image, dummy=None, delta_dummy=None)Correct an image based on the look-up table calculated ...
Parameters
• image – 2D-array with the image
• dummy – value suggested for bad pixels
• delta_dummy – precision of the dummy value
Returns corrected 2D image
reset(method=None, device=None, workgroup=None, prepare=True)reset the distortion correction and re-calculate the look-up table
Parameters
• method – can be “lut” or “csr”, “lut” looks faster
• device – can be None, “cpu” or “gpu” or the id as a 2-tuple of integer
• worgroup – enforce the workgroup size for CSR.
• prepare – set to false to only reset and not re-initialize
shape_outCalculate/cache the output shape
Returns output shape
uncorrect(image, use_cython=False)Take an image which has been corrected and transform it into it’s raw (with loss of information)
Parameters image – 2D-array with the image
Returns uncorrected 2D image
Nota: to retrieve the input mask on can do:
>>> msk = dis.uncorrect(numpy.ones(dis._shape_out)) <= 0
class pyFAI.distortion.Quad(buffer)Bases: object
Quad modelisation.
__init__(buffer)
calc_area()
calc_area_AB(I1, I2)
calc_area_BC(J1, J2)
calc_area_CD(K1, K2)
calc_area_DA(L1, L2)
6.18. distortion Module 215
![Page 220: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/220.jpg)
pyFAI Documentation, Release 0.15.0a0
calc_area_old()
calc_area_vectorial()
get_box(i, j)
get_box_size0()
get_box_size1()
get_idx(i, j)
get_offset0()
get_offset1()
init_slope()
integrateAB(start, stop, calc_area)
populate_box()
reinit(A0, A1, B0, B1, C0, C1, D0, D1)
pyFAI.distortion.test()
worker Module
This module contains the Worker class:
A tool able to perform azimuthal integration with: additional saving capabilities like
• save as 2/3D structure in a HDF5 File
• read from HDF5 files
Aims at being integrated into a plugin like LImA or as model for the GUI
The configuration of this class is mainly done via a dictionary transmitted as a JSON string: Here are the validkeys:
• “dist”
• “poni1”
• “poni2”
• “rot1”
• “rot3”
• “rot2”
• “pixel1”
• “pixel2”
• “splineFile”
• “wavelength”
• “poni” #path of the file
• “chi_discontinuity_at_0”
• “do_mask”
• “do_dark”
• “do_azimuthal_range”
• “do_flat”
216 Chapter 6. pyFAI API
![Page 221: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/221.jpg)
pyFAI Documentation, Release 0.15.0a0
• “do_2D”
• “azimuth_range_min”
• “azimuth_range_max”
• “polarization_factor”
• “nbpt_rad”
• “do_solid_angle”
• “do_radial_range”
• “do_poisson”
• “delta_dummy”
• “nbpt_azim”
• “flat_field”
• “radial_range_min”
• “dark_current”
• “do_polarization”
• “mask_file”
• “detector”
• “unit”
• “radial_range_max”
• “val_dummy”
• “do_dummy”
• “method”
class pyFAI.worker.DistortionWorker(detector=None, dark=None, flat=None, soli-dangle=None, polarization=None, mask=None,dummy=None, delta_dummy=None, device=None)
Bases: object
Simple worker doing dark, flat, solid angle and polarization correction
__init__(detector=None, dark=None, flat=None, solidangle=None, polarization=None,mask=None, dummy=None, delta_dummy=None, device=None)
Constructor of the worker :param dark: array :param flat: array :param solidangle: solid-angle array:param polarization: numpy array with 2D polarization corrections :param device: Used to influanceOpenCL behavour: can be “cpu”, “GPU”, “Acc” or even an OpenCL context
process(data, normalization_factor=1.0)Process the data and apply a normalization factor :param data: input data :param normalization: nor-malization factor :return: processed data
class pyFAI.worker.PixelwiseWorker(dark=None, flat=None, solidangle=None, po-larization=None, mask=None, dummy=None,delta_dummy=None, device=None)
Bases: object
Simple worker doing dark, flat, solid angle and polarization correction
__init__(dark=None, flat=None, solidangle=None, polarization=None, mask=None,dummy=None, delta_dummy=None, device=None)
Constructor of the worker
Parameters
• dark – array
6.19. worker Module 217
![Page 222: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/222.jpg)
pyFAI Documentation, Release 0.15.0a0
• flat – array
• solidangle – solid-angle array
• polarization – numpy array with 2D polarization corrections
• device – Used to influance OpenCL behavour: can be “cpu”, “GPU”, “Acc” or evenan OpenCL context
process(data, normalization_factor=None)Process the data and apply a normalization factor :param data: input data :param normalization: nor-malization factor :return: processed data
class pyFAI.worker.Worker(azimuthalIntegrator=None, shapeIn=(2048, 2048), shapeOut=(360,500), unit=’r_mm’, dummy=None, delta_dummy=None, azimuthalInt-grator=None)
Bases: object
__init__(azimuthalIntegrator=None, shapeIn=(2048, 2048), shapeOut=(360, 500), unit=’r_mm’,dummy=None, delta_dummy=None, azimuthalIntgrator=None)
Parameters
• AzimuthalIntegrator (azimuthalIntgrator) – py-FAI.AzimuthalIntegrator instance
• AzimuthalIntegrator – pyFAI.AzimuthalIntegrator instance (deprecated)
• shapeIn – image size in input
• shapeOut – Integrated size: can be (1,2000) for 1D integration
• unit – can be “2th_deg, r_mm or q_nm^-1 ...
do_2D()
error_model
get_config()return configuration as a dictionary
get_error_model()
get_json_config()return configuration as a JSON string
get_normalization_factor()
get_unit()
normalization_factor
process(data, normalization_factor=1.0, writer=None, metadata=None)Process a frame #TODO: dark, flat, sa are missing
Parameters
• data – numpy array containing the input image
• writer – An open writer in which ‘write’ will be called with the result of the inte-gration
reconfig(shape=(2048, 2048), sync=False)This is just to force the integrator to initialize with a given input image shape
Parameters
• shape – shape of the input image
• sync – return only when synchronized
reset()this is just to force the integrator to initialize
218 Chapter 6. pyFAI API
![Page 223: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/223.jpg)
pyFAI Documentation, Release 0.15.0a0
save_config(filename=None)
setDarkcurrentFile(imagefile)
setExtension(ext)enforce the extension of the processed data file written
setFlatfieldFile(imagefile)
setJsonConfig(jsonconfig)
setSubdir(path)Set the relative or absolute path for processed data
set_error_model(value)
set_normalization_factor(value)
set_unit(value)
unit
warmup(sync=False)Process a dummy image to ensure everything is initialized
Parameters sync – wait for processing to be finished
pyFAI.worker.make_ai(config)Create an Azimuthal integrator from the configuration stand alone function !
Parameters config – dict with all parameters
Returns configured (but uninitialized) AzimuthalIntgrator
units Module
Manages the different units
Nota for developers: this module is used a singleton to store all units in a unique manner. This explains the numberof top-level variables on the one hand and their CAPITALIZATION on the other.
class pyFAI.units.Unit(name, scale=1, label=None, equation=None, center=None, corner=None,delta=None)
Bases: object
Represents a unit.
It has at least a name and a scale (in SI-unit)
__init__(name, scale=1, label=None, equation=None, center=None, corner=None,delta=None)
Constructor of a unit.
Parameters
• name ((str)) – name of the unit
• scale ((float)) – scale of th unit to go to SI
• label ((string)) – label for nice representation in matplotlib, can use latex rep-resentation
• equation ((funct)) – equation to calculate the value from coordinates (x,y,z) indetector space. Parameters of the function are x, y, z, lambda
• center ((str)) – name of the fast-path function
get(key)Mimic the dictionary interface
6.20. units Module 219
![Page 224: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/224.jpg)
pyFAI Documentation, Release 0.15.0a0
Parameters key ((str)) – key wanted
Returns self.key
pyFAI.units.eq_2th(x, y, z, wavelength=None)Calculates the 2theta aperture of the cone
Parameters
• x – horizontal position, towards the center of the ring, from sample position
• y – Vertical position, to the roof, from sample position
• z – distance from sample along the beam
• wavelength – in meter
pyFAI.units.eq_q(x, y, z, wavelength)Calculates the modulus of the scattering vector
Parameters
• x – horizontal position, towards the center of the ring, from sample position
• y – Vertical position, to the roof, from sample position
• z – distance from sample along the beam
• wavelength – in meter
pyFAI.units.eq_r(x, y, z=None, wavelength=None)Calculates the radius
Parameters
• x – horizontal position, towards the center of the ring, from sample position
• y – Vertical position, to the roof, from sample position
• z – distance from sample along the beam
• wavelength – in meter
pyFAI.units.register_radial_unit(name, scale=1, label=None, equation=None, cen-ter=None, corner=None, delta=None)
pyFAI.units.to_unit(obj, type_=None)
utils.__init__ Module
Sub module with miscelaneous tools Utilities, mainly for image treatment
class pyFAI.utils.__init__.FixedParametersBases: set
Like a set, made for FixedParameters in geometry refinement
add_or_discard(key, value=True)Add a value to a set if value, else discard it :param key: element to added or discared from set :typevalue: boolean. If None do nothing ! :return: None
pyFAI.utils.__init__.binning(input_img, binsize, norm=True)
Parameters
• input_img – input ndarray
• binsize – int or 2-tuple representing the size of the binning
• norm – if False, do average instead of sum
Returns binned input ndarray
220 Chapter 6. pyFAI API
![Page 225: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/225.jpg)
pyFAI Documentation, Release 0.15.0a0
pyFAI.utils.__init__.calc_checksum(ary, safe=True)Calculate the checksum by default (or returns its buffer location if unsafe)
pyFAI.utils.__init__.center_of_mass(img)Calculate the center of mass of of the array. Like scipy.ndimage.measurements.center_of_mass :param img:2-D array :return: 2-tuple of float with the center of mass
pyFAI.utils.__init__.convert_CamelCase(name)convert a function name in CamelCase into camel_case
pyFAI.utils.__init__.deg2rad(dd)Convert degrees to radian in the range -pi->pi
Parameters dd – angle in degrees
Nota: depending on the platform it could be 0<2pi A branch is cheaper than a trigo operation
pyFAI.utils.__init__.dog(s1, s2, shape=None)2D difference of gaussian typically 1 to 10 parameters
pyFAI.utils.__init__.dog_filter(input_img, sigma1, sigma2, mode=’reflect’, cval=0.0)2-dimensional Difference of Gaussian filter implemented with FFT
Parameters
• input_img (array-like) – input_img array to filter
• sigma (scalar or sequence of scalars) – standard deviation for Gaussiankernel. The standard deviations of the Gaussian filter are given for each axis as a se-quence, or as a single number, in which case it is equal for all axes.
• mode – {‘reflect’,’constant’,’nearest’,’mirror’, ‘wrap’}, optional The mode parameterdetermines how the array borders are handled, where cval is the value when mode isequal to ‘constant’. Default is ‘reflect’
• cval – scalar, optional Value to fill past edges of input if mode is ‘constant’. Defaultis 0.0
pyFAI.utils.__init__.expand(input_img, sigma, mode=’constant’, cval=0.0)Expand array a with its reflection on boundaries
Parameters
• a – 2D array
• sigma – float or 2-tuple of floats.
• mode – “constant”, “nearest”, “reflect” or “mirror”
• cval – filling value used for constant, 0.0 by default
Nota: sigma is the half-width of the kernel. For gaussian convolution it is adviced that it is4*sigma_of_gaussian
pyFAI.utils.__init__.expand2d(vect, size2, vertical=True)This expands a vector to a 2d-array.
The result is the same as:
if vertical:numpy.outer(numpy.ones(size2), vect)
else:numpy.outer(vect, numpy.ones(size2))
This is a ninja optimization: replace *1 with a memcopy, saves 50% of time at the ms level.
Parameters
• vect – 1d vector
• size2 – size of the expanded dimension
6.21. utils.__init__ Module 221
![Page 226: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/226.jpg)
pyFAI Documentation, Release 0.15.0a0
• vertical – if False the vector is expanded to the first dimension. If True, it is ex-panded to the second dimension.
pyFAI.utils.__init__.expand_args(args)Takes an argv and expand it (under Windows, cmd does not convert *.tif into a list of files. Keeps onlyvalid files (thanks to glob)
Parameters args – list of files or wilcards
Returns list of actual args
pyFAI.utils.__init__.float_(val)Convert anything to a float ... or None if not applicable
pyFAI.utils.__init__.fully_qualified_name(obj)Return the fully qualified name of an object
pyFAI.utils.__init__.gaussian(M, std)Return a Gaussian window of length M with standard-deviation std.
This differs from the scipy.signal.gaussian implementation as: - The default for sym=False (needed forgaussian filtering without shift) - This implementation is normalized
Parameters
• M – length of the windows (int)
• std – standatd deviation sigma
The FWHM is 2*numpy.sqrt(2 * numpy.pi)*std
pyFAI.utils.__init__.gaussian_filter(input_img, sigma, mode=’reflect’, cval=0.0,use_scipy=True)
2-dimensional Gaussian filter implemented with FFT
Parameters
• input_img (array-like) – input array to filter
• sigma (scalar or sequence of scalars) – standard deviation for Gaussiankernel. The standard deviations of the Gaussian filter are given for each axis as a se-quence, or as a single number, in which case it is equal for all axes.
• mode – {‘reflect’,’constant’,’nearest’,’mirror’, ‘wrap’}, optional The mode parameterdetermines how the array borders are handled, where cval is the value when mode isequal to ‘constant’. Default is ‘reflect’
• cval – scalar, optional Value to fill past edges of input if mode is ‘constant’. Defaultis 0.0
pyFAI.utils.__init__.get_calibration_dir()get the full path of a calibration directory
Returns the full path of the calibrant file
pyFAI.utils.__init__.get_cl_file(filename)get the full path of a openCL file
Returns the full path of the openCL source file
pyFAI.utils.__init__.get_ui_file(filename)get the full path of a user-interface file
Returns the full path of the ui
pyFAI.utils.__init__.int_(val)Convert anything to an int ... or None if not applicable
pyFAI.utils.__init__.is_far_from_group(pt, lst_pts, d2)Tells if a point is far from a group of points, distance greater than d2 (distance squared)
222 Chapter 6. pyFAI API
![Page 227: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/227.jpg)
pyFAI Documentation, Release 0.15.0a0
Parameters
• pt – point of interest
• lst_pts – list of points
• d2 – minimum distance squarred
Returns True If the point is far from all others.
class pyFAI.utils.__init__.lazy_property(fget)Bases: object
meant to be used for lazy evaluation of an object attribute. property should represent non-mutable data, asit replaces itself.
__init__(fget)
pyFAI.utils.__init__.maximum_position(img)Same as scipy.ndimage.measurements.maximum_position: Find the position of the maximum of the valuesof the array.
Parameters img – 2-D image
Returns 2-tuple of int with the position of the maximum
pyFAI.utils.__init__.measure_offset(img1, img2, method=’numpy’, withLog=False, with-Corr=False)
Measure the actual offset between 2 images :param img1: ndarray, first image :param img2: ndarray, secondimage, same shape as img1 :param withLog: shall we return logs as well ? boolean :return: tuple of floatswith the offsets
pyFAI.utils.__init__.readFloatFromKeyboard(text, dictVar)Read float from the keyboard ....
Parameters
• text – string to be displayed
• dictVar – dict of this type: {1: [set_dist_min],3: [set_dist_min, set_dist_guess,set_dist_max]}
pyFAI.utils.__init__.relabel(label, data, blured, max_size=None)Relabel limits the number of region in the label array. They are ranked relatively to their max(I0)-max(blur(I0)
Parameters
• label – a label array coming out of scipy.ndimage.measurement.label
• data – an array containing the raw data
• blured – an array containing the blurred data
• max_size – the max number of label wanted
Returns array like label
pyFAI.utils.__init__.roundfft(N)This function returns the integer >=N for which size the Fourier analysis is faster (fron the FFT point ofview) Credit: Alessandro Mirone, ESRF, 2012
Parameters N – interger on which one would like to do a Fourier transform
Returns integer with a better choice
pyFAI.utils.__init__.shift(input_img, shift_val)Shift an array like scipy.ndimage.interpolation.shift(input_img, shift_val, mode=”wrap”, order=0) but faster:param input_img: 2d numpy array :param shift_val: 2-tuple of integers :return: shifted image
6.21. utils.__init__ Module 223
![Page 228: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/228.jpg)
pyFAI Documentation, Release 0.15.0a0
pyFAI.utils.__init__.shiftFFT(input_img, shift_val, method=’fft’)Do shift using FFTs
Shift an array like scipy.ndimage.interpolation.shift(input, shift, mode=”wrap”, order=”infinity”) but faster:param input_img: 2d numpy array :param shift_val: 2-tuple of float :return: shifted image
pyFAI.utils.__init__.str_(val)Convert anything to a string ... but None -> “”
pyFAI.utils.__init__.unBinning(binnedArray, binsize, norm=True)
Parameters
• binnedArray – input ndarray
• binsize – 2-tuple representing the size of the binning
• norm – if True (default) decrease the intensity by binning factor. If False, it is non-conservative
Returns unBinned input ndarray
utils.bayes Module
Tool for bayesian filtering-out of positive peaks Bayesian evaluation of background for 1D powder diffractionpattern
Code according to Sivia and David, J. Appl. Cryst. (2001). 34, 318-324 # Version: 0.1 2012/03/28 # Version: 0.22016/10/07: OOP implementation
class pyFAI.utils.bayes.BayesianBackgroundBases: object
This class estimates the background of a powder diffraction pattern
http://journals.iucr.org/j/issues/2001/03/00/he0278/he0278.pdf
The log likelihood is described in correspond to eq7 of the paper: z = y/sigma^2 * if z<0: a quadraticbehaviour is expected * if z>>1 it is likely a bragg peak so the penalty should be small: log(z). * The splineis used to have a quadratic behaviour near 0 and the log one
near the junction
The threshold is taken at 8 as erf is 1 above 6: The points 6, 7 and 8 are used in the spline to ensure acontinuous junction with the logarithmic continuation
PREFACTOR = 1
__init__()
background_image(img, sigma=None, mask=None, npt=10, k=3)
classmethod bayes_llk(z)Calculate actually the log-likelihood from a set of weighted error
Re implementation of: (y<=0)*5*y**2 + (y>0)*(y<8)*pyFAI.utils.bayes.background.spline(y) +(y>=8)*(s1+log(abs(y)+1*(y<8))) even slightly faster
:param float[:] z: weighted error :return: log likelihood :rtype: float[:]
classmethod bayes_llk_large(z)used to calculate the log-likelihood of large positive values: logarithmic
classmethod bayes_llk_negative(z)used to calculate the log-likelihood of negative values: quadratic
classmethod bayes_llk_small(z)used to calculate the log-likelihood of small positive values: fitted with spline
classmethod classinit()
224 Chapter 6. pyFAI API
![Page 229: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/229.jpg)
pyFAI Documentation, Release 0.15.0a0
classmethod func2d_min(values, d0_sparse, d1_sparse, d0_pos, d1_pos, y_obs, w_obs, valid, k)Function to optimize
Parameters
• values – values of the background on spline knots
• d0_sparse – positions along slowest axis of the spline knots
• d1_pos – positions along fastest axis of the spline knots
• d0_pos – positions along slowest axis (all coordinates)
• d1_pos – positions along fastest axis (all coordinates)
• y_obs – intensities actually measured
• w_obs – weights of the experimental points
• valid – coordinated of valid pixels
• k – order of the spline, usually 3
Returns sum of the log-likelihood to be minimized
classmethod func_min(y0, x_obs, y_obs, w_obs, x0, k)Function to optimize
Parameters
• y0 – values of the background
• x_obs – experimental values
• y_obs – experimental values
• w_obs – weights of the experimental points
• x0 – position of evaluation of the spline
• k – order of the spline, usually 3
Returns sum of the log-likelihood to be minimized
s1 = 2.5435828321944816
spline = <scipy.interpolate.fitpack2.InterpolatedUnivariateSpline object>
classmethod test_bayes_llk()Test plot of log(likelihood) Similar to as figure 3 of Sivia and David, J. Appl. Cryst. (2001). 34,318-324
utils.shell Module
Contains the progress-bar in the shell command line Module containing utilities around shell
class pyFAI.utils.shell.ProgressBar(title, max_value, bar_width)Progress bar in shell mode
__init__(title, max_value, bar_width)Create a progress bar using a title, a maximum value and a graphical size.
The display is done with stdout using carriage return to to hide the previous progress. It is not possibleto use stdout for something else whill a progress bar is in use.
The result looks like:
Parameters
• title (str) – Title displayed before the progress bar
• max_value (float) – The maximum value of the progress bar
6.21. utils.__init__ Module 225
![Page 230: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/230.jpg)
pyFAI Documentation, Release 0.15.0a0
• bar_width (int) – Size of the progressbar in the screen
clear()Remove the progress bar from the display and move the cursor at the beginning of the line usingcarriage return.
update(value, message=’‘)Update the progrss bar with the progress bar’s current value.
Set the progress bar’s current value, compute the percentage of progress and update the screen with.Carriage return is used first and then the content of the progress bar. The cursor is at the begining ofthe line.
Parameters
• value (float) – progress bar’s current value
• message (str) – message displayed after the progress bar
utils.stringutil Module
Enhanced string formatter Module containing utilitary around string
class pyFAI.utils.stringutil.SafeFormatterBases: string.Formatter
Like default formater but unmatched keys are still present into the result string
get_field(field_name, args, kwargs)
pyFAI.utils.stringutil.safe_format(format_string, arguments)Like default str.format but unmatching patterns will be still present into the result string.
Parameters
• str (format_string) – Format string as defined in the default formatter.
• dictor tuple (arguments) – Arbitrary set of positional and keyword arguments.
Return type str
opencl.__init__ Module
Contains all OpenCL implementation.
opencl.common Module
class pyFAI.opencl.common.mfBases: object
READ_ONLY = 1
READ_WRITE = 1
WRITE_ONLY = 1
pyFAI.opencl.common.release_cl_buffers(cl_buffers)
Parameters cl_buffer (dict(str, pyopencl.Buffer)) – the buffer you want to re-lease
This method release the memory of the buffers store in the dict
pyFAI.opencl.common.allocate_cl_buffers(buffers, device=None, context=None)
Parameters buffers – the buffers info use to create the pyopencl.Buffer
226 Chapter 6. pyFAI API
![Page 231: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/231.jpg)
pyFAI Documentation, Release 0.15.0a0
Returns a dict containing the instanciated pyopencl.Buffer
Return type dict(str, pyopencl.Buffer)
This method instanciate the pyopencl.Buffer from the buffers description.
pyFAI.opencl.common.measure_workgroup_size(device)Measure the actual size of the workgroup
Parameters device – device or context or 2-tuple with indexes
Returns the actual measured workgroup size
if device is “all”, returns a dict with all devices with their ids as keys.
pyFAI.opencl.common.kernel_workgroup_size(program, kernel)Extract the compile time maximum workgroup size
Parameters
• program – OpenCL program
• kernel – kernel or name of the kernel
Returns the maximum acceptable workgroup size for the given kernel
opencl.processing Module
Common OpenCL abstract base classes for different processing
class pyFAI.opencl.processing.BufferDescription(name, size, dtype, flags)Bases: tuple
dtypeAlias for field number 2
flagsAlias for field number 3
nameAlias for field number 0
sizeAlias for field number 1
class pyFAI.opencl.processing.EventDescription(name, event)Bases: tuple
eventAlias for field number 1
nameAlias for field number 0
class pyFAI.opencl.processing.OpenclProcessing(ctx=None, devicetype=’all’, plat-formid=None, deviceid=None,block_size=None, profile=False)
Bases: object
Abstract class for different types of OpenCL processing.
This class provides: * Generation of the context, queues, profiling mode * Additional function to allo-cate/free all buffers declared as static attributes of the class * Functions to compile kernels, cache them andclean them * helper functions to clone the object
__init__(ctx=None, devicetype=’all’, platformid=None, deviceid=None, block_size=None, pro-file=False)
Constructor of the abstract OpenCL processing class
Parameters
6.22. opencl.__init__ Module 227
![Page 232: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/232.jpg)
pyFAI Documentation, Release 0.15.0a0
• ctx – actual working context, left to None for automatic initialization from devicetype or platformid/deviceid
• devicetype – type of device, can be “CPU”, “GPU”, “ACC” or “ALL”
• platformid – integer with the platform_identifier, as given by clinfo
• deviceid – Integer with the device identifier, as given by clinfo
• block_size – preferred workgroup size, may vary depending on the outpcome ofthe compilation
• profile – switch on profiling to be able to profile at the kernel level, store profilingelements (makes code slightly slower)
allocate_buffers(buffers=None)Allocate OpenCL buffers required for a specific configuration
Parameters buffers – a list of BufferDescriptions, leave to None for paramatrizedbuffers.
Note that an OpenCL context also requires some memory, as well as Event and other OpenCL func-tionalities which cannot and are not taken into account here. The memory required by a context variesdepending on the device. Typical for GTX580 is 65Mb but for a 9300m is ~15Mb In addition, a GPUwill always have at least 3-5Mb of memory in use. Unfortunately, OpenCL does NOT have a built-inway to check the actual free memory on a device, only the total memory.
buffers = [BufferDescription(name=’output’, size=10, dtype=<type ‘numpy.float32’>, flags=None)]
compile_kernels(kernel_files=None, compile_options=None)Call the OpenCL compiler
Parameters kernel_files – list of path to the kernel (by default use the one declared inthe class)
free_buffers()free all device.memory allocated on the device
free_kernels()Free all kernels
kernel_files = []
log_profile()If we are in profiling mode, prints out all timing for every single OpenCL call
reset_profile()Resets the profiling timers
set_profiling(value=True)Switch On/Off the profiling flag of the command queue to allow debugging
Parameters value – set to True to enable profiling, or to False to disable it. Withoutprofiling, the processing is marginally faster
Profiling information can then be retrieved with the ‘log_profile’ method
opencl.preproc Module
OpenCL implementation of the preproc module
228 Chapter 6. pyFAI API
![Page 233: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/233.jpg)
pyFAI Documentation, Release 0.15.0a0
class pyFAI.opencl.preproc.OCL_Preproc(image_size=None, image_dtype=None, im-age=None, dark=None, flat=None, soli-dangle=None, polarization=None, absorp-tion=None, mask=None, dummy=None,delta_dummy=None, empty=None,split_result=False, calc_variance=False, pois-sonian=False, ctx=None, devicetype=’all’, plat-formid=None, deviceid=None, block_size=32,profile=False)
Bases: pyFAI.opencl.processing.OpenclProcessing
OpenCL class for pre-processing ... mainly for demonstration
__init__(image_size=None, image_dtype=None, image=None, dark=None, flat=None, sol-idangle=None, polarization=None, absorption=None, mask=None, dummy=None,delta_dummy=None, empty=None, split_result=False, calc_variance=False, pois-sonian=False, ctx=None, devicetype=’all’, platformid=None, deviceid=None,block_size=32, profile=False)
Parameters
• image_size – (int) number of element of the input image
• image_dtype – dtype of the input image
• image – retrieve image_size and image_dtype from template
• dark – dark current image as numpy array
• flat – flat field image as numpy array
• solidangle – solid angle image as numpy array
• absorption – absorption image as numpy array
• mask – array of int8 with 0 where the data are valid
• dummy – value of impossible values: dynamic mask
• delta_dummy – precision for dummy values
• empty – value to be assigned to pixel without contribution (i.e masked)
• split_result – return the result a tuple: data, [variance], normalization, so thelast dim becomes 2 or 3
• calc_variance – report the result as data, variance, normalization
• poissonian – assumes poisson law for data and dark,
• ctx – actual working context, left to None for automatic initialization from devicetype or platformid/deviceid
• devicetype – type of device, can be “CPU”, “GPU”, “ACC” or “ALL”
• platformid – integer with the platform_identifier, as given by clinfo
• deviceid – Integer with the device identifier, as given by clinfo
• block_size – preferred workgroup size, may vary depending on the outpcome ofthe compilation
• profile – switch on profiling to be able to profile at the kernel level, store profilingelements (makes code slower)
buffers = [BufferDescription(name=’output’, size=3, dtype=<type ‘numpy.float32’>, flags=1), BufferDescription(name=’image_raw’, size=1, dtype=<type ‘numpy.float32’>, flags=1), BufferDescription(name=’image’, size=1, dtype=<type ‘numpy.float32’>, flags=1), BufferDescription(name=’variance’, size=1, dtype=<type ‘numpy.float32’>, flags=1), BufferDescription(name=’dark’, size=1, dtype=<type ‘numpy.float32’>, flags=1), BufferDescription(name=’dark_variance’, size=1, dtype=<type ‘numpy.float32’>, flags=1), BufferDescription(name=’flat’, size=1, dtype=<type ‘numpy.float32’>, flags=1), BufferDescription(name=’polarization’, size=1, dtype=<type ‘numpy.float32’>, flags=1), BufferDescription(name=’solidangle’, size=1, dtype=<type ‘numpy.float32’>, flags=1), BufferDescription(name=’absorption’, size=1, dtype=<type ‘numpy.float32’>, flags=1), BufferDescription(name=’mask’, size=1, dtype=<type ‘numpy.int8’>, flags=1)]
compile_kernels(kernel_files=None, compile_options=None)Call the OpenCL compiler
6.22. opencl.__init__ Module 229
![Page 234: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/234.jpg)
pyFAI Documentation, Release 0.15.0a0
Parameters kernel_files – list of path to the kernel (by default use the one declared inthe class)
delta_dummy
dummy
empty
kernel_files = [’preprocess.cl’]
mapping = {<type ‘numpy.uint32’>: ‘u32_to_float’, <type ‘numpy.int32’>: ‘s32_to_float’, <type ‘numpy.uint8’>: ‘u8_to_float’, <type ‘numpy.int8’>: ‘s8_to_float’, <type ‘numpy.uint16’>: ‘u16_to_float’, <type ‘numpy.int16’>: ‘s16_to_float’}
process(image, dark=None, variance=None, dark_variance=None, normalization_factor=1.0)Perform the pixel-wise operation of the array
Parameters
• raw – numpy array with the input image
• dark – numpy array with the dark-current image
• variance – numpy array with the variance of input image
• dark_variance – numpy array with the variance of dark-current image
• normalization_factor – divide the result by this
Returns array with processed data, may be an array of (data,variance,normalization) de-pending on class initialization
send_buffer(data, dest)Send a numpy array to the device
Parameters
• data – numpy array with data
• dest – name of the buffer as registered in the class
set_kernel_arguments()Tie arguments of OpenCL kernel-functions to the actual kernels
pyFAI.opencl.preproc.preproc(raw, dark=None, flat=None, solidangle=None, polariza-tion=None, absorption=None, mask=None, dummy=None,delta_dummy=None, normalization_factor=1.0, empty=None,split_result=False, variance=None, dark_variance=None,poissonian=False, dtype=<type ‘numpy.float32’>)
Common preprocessing step, implemented using OpenCL. May be inefficient
Parameters
• data – raw value, as a numpy array, 1D or 2D
• mask – array non null where data should be ignored
• dummy – value of invalid data
• delta_dummy – precision for invalid data
• dark – array containing the value of the dark noise, to be subtracted
• flat – Array containing the flatfield image. It is also checked for dummies if relevant.
• solidangle – the value of the solid_angle. This processing may be performed duringthe rebinning instead. left for compatibility
• polarization – Correction for polarization of the incident beam
• absorption – Correction for absorption in the sensor volume
• normalization_factor – final value is divided by this
• empty – value to be given for empty pixels
230 Chapter 6. pyFAI API
![Page 235: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/235.jpg)
pyFAI Documentation, Release 0.15.0a0
• split_result – set to true to separate numerator from denominator and return anarray of float2 or float3 (with variance)
• variance – provide an estimation of the variance, enforce split_result=True and re-turn an float3 array with variance in second position.
• poissonian – set to “True” for assuming the detector is poissonian and variance =raw + dark
• dtype – dtype for all processing
All calculation are performed in single precision floating point (32 bits).
NaN are always considered as invalid values
if neither empty nor dummy is provided, empty pixels are 0. Empty pixels are always zero in “split_result”mode
Split result:
•When set to False, i.e the default, the pixel-wise operation is: I = (raw - dark)/(flat * solidangle *polarization * absorption) Invalid pixels are set to the dummy or empty value.
•When split_ressult is set to True, each result result is a float2 or a float3 (with an additional value forthe variance) as such:
I = [(raw - dark), (variance), (flat * solidangle * polarization * absorption)]
Empty pixels will have all their 2 or 3 values to 0 (and not to dummy or empty value)
•If poissonian is set to True, the variance is evaluated as (raw + dark)
opencl.azim_hist Module
opencl.azim_lut Module
opencl.azim_csr Module
gui.__init__ Module
Set of Qt widgets
gui.matplotlib Module
Initialize properly Matplotlib
gui.qt Module
gui.utils Module
ext.__init__ Module
Sub-module with all Cython binary extensions
6.23. gui.__init__ Module 231
![Page 236: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/236.jpg)
pyFAI Documentation, Release 0.15.0a0
ext.bilinear Module
This extension makes a discrete 2D-array appear like a continuous function thanks to bilinear interpolations.
class pyFAI.ext.bilinear.BilinearBases: object
Bilinear interpolator for finding max.
Instance attribute defined in pxd file
cp_local_maxi(self, size_t x)→ size_t
data
f_cy(self, x)Function -f((y,x)) where f is a continuous function (y,x) are pixel coordinates pixels outside the imageare given an arbitrary high value to help the minimizer
Parameters x – 2-tuple of float
Returns Interpolated negative signal from the image
(negative for using minimizer to search for peaks)
height
local_maxi(self, x)Return the local maximum with sub-pixel refinement.
Sub-pixel refinement: Second order Taylor expansion of the function; first derivative is null
𝑑𝑒𝑙𝑡𝑎 = 𝑥− 𝑖 = −𝐼𝑛𝑣𝑒𝑟𝑠𝑒[𝐻𝑒𝑠𝑠𝑖𝑎𝑛].𝑔𝑟𝑎𝑑𝑖𝑒𝑛𝑡
If Hessian is singular or |𝑑𝑒𝑙𝑡𝑎| > 1: use a center of mass.
Parameters
• x – 2-tuple of integers
• w – half with of the window: 1 or 2 are advised
Returns 2-tuple of float with the nearest local maximum
maxi
mini
width
pyFAI.ext.bilinear.calc_cartesian_positionsCalculate the Cartesian position for array of position (d1, d2) with pixel coordinated stored in array pos.This is bilinear interpolation.
Parameters
• d1 – position in dim1
• d2 – position in dim2
• pos – array with position of pixels corners
Returns 3-tuple of position.
pyFAI.ext.bilinear.convert_corner_2D_to_4DConvert 2 (or 3) arrays of corner position into a 4D array of pixel corner coordinates
Parameters
• ndim – 2d or 3D output
• d1 – 2D position in dim1 (shape +1)
232 Chapter 6. pyFAI API
![Page 237: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/237.jpg)
pyFAI Documentation, Release 0.15.0a0
• d2 – 2D position in dim2 (shape +1)
• d3 – 2D position in dim3 (z) (shape +1)
Returns pos 4D array with position of pixels corners
ext._bispev Module
This extension is a re-implementation of bi-cubic spline evaluation from scipy Spline evaluation function
Created on Nov 4, 2013
pyFAI.ext._bispev.bisplev(x, y, tck, dx=0, dy=0)Evaluate a bivariate B-spline and its derivatives.
Return a rank-2 array of spline function values (or spline derivative values) at points given by the cross-product of the rank-1 arrays x and y. In special cases, return an array or just a float if either x or y or bothare floats. Based on BISPEV from FITPACK.
See bisplrep() to generate the tck representation.
See also splprep(), splrep(), splint(), sproot(), splev(), UnivariateSpline(),BivariateSpline()
Parameters
• x (ndarray) – Rank-1 arrays specifying the domain over which to evaluate the splineor its derivative.
• y (ndarray) – Rank-1 arrays specifying the domain over which to evaluate the splineor its derivative.
• tck (tuple) – A sequence of length 5 returned by bisplrep containing the knot loca-tions, the coefficients, and the degree of the spline: [tx, ty, c, kx, ky].
• dx (int) – The orders of the partial derivatives in x. This version does not implementderivatives.
• dy (int) – The orders of the partial derivatives in y. This version does not implementderivatives.
Return type ndarray
Returns The B-spline or its derivative evaluated over the set formed by the cross-product of xand y.
ext._blob Module
Blob detection is used to find peaks in images by performing subsequent blurs Some Cythonized function forblob detection function
pyFAI.ext._blob.local_max(__Pyx_memviewslice dogs, mask=None, bool n_5=False)Calculate if a point is a maximum in a 3D space: (scale, y, x)
Parameters
• dogs – 3D array of difference of gaussian
• mask – mask with invalid pixels
• N_5 – take a neighborhood of 5x5 pixel in plane
Returns 3d_array with 1 where is_max
6.24. ext.__init__ Module 233
![Page 238: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/238.jpg)
pyFAI Documentation, Release 0.15.0a0
ext._convolution Module
Convolutions in real space are used to blurs images, used in blob-detection algorithm Implementation of a sepa-rable 2D convolution
pyFAI.ext._convolution.gaussian(sigma, width=None)Return a Gaussian window of length “width” with standard-deviation “sigma”.
Parameters
• sigma – standard deviation sigma
• width – length of the windows (int) By default 8*sigma+1,
Width should be odd.
The FWHM is 2*sqrt(2 * pi)*sigma
pyFAI.ext._convolution.gaussian_filter(img, sigma)Performs a gaussian bluring using a gaussian kernel.
Parameters
• img – input image
• sigma – width parameter of the gaussian
pyFAI.ext._convolution.horizontal_convolution(__Pyx_memviewslice img,__Pyx_memviewslice filter)
Implements a 1D horizontal convolution with a filter. The only implemented mode is “reflect” (default inscipy.ndimage.filter)
Parameters
• img – input image
• filter – 1D array with the coefficients of the array
Returns array of the same shape as image with
pyFAI.ext._convolution.vertical_convolution(__Pyx_memviewslice img,__Pyx_memviewslice filter)
Implements a 1D vertical convolution with a filter. The only implemented mode is “reflect” (default inscipy.ndimage.filter)
Parameters
• img – input image
• filter – 1D array with the coefficients of the array
Returns array of the same shape as image with
ext._distortion Module
Distortion correction are correction are applied by Look-up table (or CSR)
class pyFAI.ext._distortion.DistortionBases: object
This class applies a distortion correction on an image.
It is also able to apply an inversion of the correction.
__init__(self, detector=’detector’, shape=None)
Parameters detector – detector instance or detector name
calc_LUT(self)
234 Chapter 6. pyFAI API
![Page 239: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/239.jpg)
pyFAI Documentation, Release 0.15.0a0
calc_LUT_size(self)Considering the “half-CCD” spline from ID11 which describes a (1025,2048) detector, the physicallocation of pixels should go from: [-17.48634 : 1027.0543, -22.768829 : 2028.3689] We chose todiscard pixels falling outside the [0:1025,0:2048] range with a lose of intensity
We keep self.pos: pos_corners will not be compatible with systems showing non adjacent pixels (likesome xpads)
calc_pos(self)
correct(self, image)Correct an image based on the look-up table calculated ...
Parameters image – 2D-array with the image
Returns corrected 2D image
uncorrect(self, image)Take an image which has been corrected and transform it into it’s raw (with loss of information)
Parameters image – 2D-array with the image
Returns uncorrected 2D image and a mask (pixels in raw image
pyFAI.ext._distortion.calc_CSR(__Pyx_memviewslice pos, shape, bin_size, max_pixel_size,__Pyx_memviewslice mask=None)
Calculate the Look-up table as CSR format
Parameters
• pos – 4D position array
• shape – output shape
• bin_size – number of input element per output element (as numpy array)
• max_pixel_size – (2-tuple of int) size of a buffer covering the largest pixel
Returns look-up table in CSR format: 3-tuple of array
pyFAI.ext._distortion.calc_LUT(__Pyx_memviewslice pos, shape, bin_size, max_pixel_size,__Pyx_memviewslice mask=None)
Parameters
• pos – 4D position array
• shape – output shape
• bin_size – number of input element per output element (numpy array)
• max_pixel_size – (2-tuple of int) size of a buffer covering the largest pixel
• mask – arry with bad pixels marked as True
Returns look-up table
pyFAI.ext._distortion.calc_area(float I1, float I2, float slope, float intercept)→ floatCalculate the area between I1 and I2 of a line with a given slope & intercept
pyFAI.ext._distortion.calc_openmp(__Pyx_memviewslice pos, shape, max_pixel_size=(8,8), __Pyx_memviewslice mask=None, format=’csr’, intbins_per_pixel=8)
Calculate the look-up table (or CSR) using OpenMP
Parameters
• pos – 4D position array
• shape – output shape
• max_pixel_size – (2-tuple of int) size of a buffer covering the largest pixel
• format – can be “CSR” or “LUT”
6.24. ext.__init__ Module 235
![Page 240: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/240.jpg)
pyFAI Documentation, Release 0.15.0a0
• bins_per_pixel – average splitting factor (number of pixels per bin)
Returns look-up table in CSR/LUT format
pyFAI.ext._distortion.calc_posCalculate the pixel boundary position on the regular grid
Parameters
• pixel_corners – pixel corner coordinate as detector.get_pixel_corner()
• shape – requested output shape. If None, it is calculated
• pixel2 (pixel1,) – pixel size along row and column coordinates
Returns pos, delta1, delta2, shape_out, offset
pyFAI.ext._distortion.calc_sizeCalculate the number of items per output pixel
Parameters
• pos – 4D array with position in space
• shape – shape of the output array
• mask – input data mask
• offset – 2-tuple of float with the minimal index of
Returns number of input element per output elements
pyFAI.ext._distortion.clip(int value, int min_val, int max_val)→ intLimits the value to bounds
pyFAI.ext._distortion.correct_CSR(image, shape_in, shape_out, LUT, dummy=None,delta_dummy=None)
Correct an image based on the look-up table calculated ...
Parameters
• image – 2D-array with the image
• shape_in – shape of input image
• shape_out – shape of output image
• LUT – Look up table, here a 3-tuple array of ndarray
• dummy – value for invalid pixels
• delta_dummy – precision for invalid pixels
Returns corrected 2D image
pyFAI.ext._distortion.correct_LUT(image, shape_in, shape_out, __Pyx_memviewslice LUT,dummy=None, delta_dummy=None)
Correct an image based on the look-up table calculated ...
Parameters
• image – 2D-array with the image
• shape_in – shape of input image
• shape_out – shape of output image
• LUT – Look up table, here a 2D-array of struct
• dummy – value for invalid pixels
• delta_dummy – precision for invalid pixels
Returns corrected 2D image
236 Chapter 6. pyFAI API
![Page 241: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/241.jpg)
pyFAI Documentation, Release 0.15.0a0
pyFAI.ext._distortion.uncorrect_CSR(image, shape, LUT)Take an image which has been corrected and transform it into it’s raw (with loss of information)
Parameters
• image – 2D-array with the image
• shape – shape of output image
• LUT – Look up table, here a 3-tuple of ndarray
Returns uncorrected 2D image and a mask (pixels in raw image not existing)
pyFAI.ext._distortion.uncorrect_LUT(image, shape, __Pyx_memviewslice LUT)Take an image which has been corrected and transform it into it’s raw (with loss of information)
Parameters
• image – 2D-array with the image
• shape – shape of output image
• LUT – Look up table, here a 2D-array of struct
Returns uncorrected 2D image and a mask (pixels in raw image not existing)
ext._geometry Module
This extension is a fast-implementation for calculating the geometry, i.e. where every pixel of an array stays inspace (x,y,z) or its (r, chi) coordinates.
pyFAI.ext._geometry.calc_chi(double L, double rot1, double rot2, double rot3, ndarray pos1,ndarray pos2, ndarray pos3=None)
Calculate the chi array (azimuthal angles) using OpenMP
X1 = p1*cos(rot2)*cos(rot3) + p2*(cos(rot3)*sin(rot1)*sin(rot2) - cos(rot1)*sin(rot3))- L*(cos(rot1)*cos(rot3)*sin(rot2) + sin(rot1)*sin(rot3)) X2 = p1*cos(rot2)*sin(rot3)- L*(-(cos(rot3)*sin(rot1)) + cos(rot1)*sin(rot2)*sin(rot3)) + p2*(cos(rot1)*cos(rot3) +sin(rot1)*sin(rot2)*sin(rot3)) X3 = -(L*cos(rot1)*cos(rot2)) + p2*cos(rot2)*sin(rot1) - p1*sin(rot2)tan(Chi) = X2 / X1
Parameters
• L – distance sample - PONI
• rot1 – angle1
• rot2 – angle2
• rot3 – angle3
• pos1 – numpy array with distances in meter along dim1 from PONI (Y)
• pos2 – numpy array with distances in meter along dim2 from PONI (X)
• pos3 – numpy array with distances in meter along Sample->PONI (Z), positive behindthe detector
Returns ndarray of double with same shape and size as pos1
pyFAI.ext._geometry.calc_cosa(double L, ndarray pos1, ndarray pos2, ndarray pos3=None)Calculate the cosine of the incidence angle using OpenMP. Used for sensors thickness effect corrections
Parameters
• L – distance sample - PONI
• pos1 – numpy array with distances in meter along dim1 from PONI (Y)
• pos2 – numpy array with distances in meter along dim2 from PONI (X)
6.24. ext.__init__ Module 237
![Page 242: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/242.jpg)
pyFAI Documentation, Release 0.15.0a0
• pos3 – numpy array with distances in meter along Sample->PONI (Z), positive behindthe detector
Returns ndarray of double with same shape and size as pos1
pyFAI.ext._geometry.calc_delta_chiCalculate the delta chi array (azimuthal angles) using OpenMP
Parameters
• centers – numpy array with chi angles of the center of the pixels
• corners – numpy array with chi angles of the corners of the pixels
Returns ndarray of double with same shape and size as centers woth the delta chi per pixel
pyFAI.ext._geometry.calc_pos_zyx(double L, double poni1, double poni2, double rot1, doublerot2, double rot3, ndarray pos1, ndarray pos2, ndarraypos3=None)
Calculate the 3D coordinates in the sample’s referential
Parameters
• L – distance sample - PONI
• poni1 – PONI coordinate along y axis
• poni2 – PONI coordinate along x axis
• rot1 – angle1
• rot2 – angle2
• rot3 – angle3
• pos1 – numpy array with distances in meter along dim1 from PONI (Y)
• pos2 – numpy array with distances in meter along dim2 from PONI (X)
• pos3 – numpy array with distances in meter along Sample->PONI (Z), positive behindthe detector
Returns 3-tuple of ndarray of double with same shape and size as pos1
pyFAI.ext._geometry.calc_q(double L, double rot1, double rot2, double rot3, ndarray pos1,ndarray pos2, double wavelength, pos3=None)
Calculate the q (scattering vector) array using OpenMP
X1 = p1*cos(rot2)*cos(rot3) + p2*(cos(rot3)*sin(rot1)*sin(rot2) - cos(rot1)*sin(rot3))- L*(cos(rot1)*cos(rot3)*sin(rot2) + sin(rot1)*sin(rot3)) X2 = p1*cos(rot2)*sin(rot3)- L*(-(cos(rot3)*sin(rot1)) + cos(rot1)*sin(rot2)*sin(rot3)) + p2*(cos(rot1)*cos(rot3) +sin(rot1)*sin(rot2)*sin(rot3)) X3 = -(L*cos(rot1)*cos(rot2)) + p2*cos(rot2)*sin(rot1) - p1*sin(rot2)tan(Chi) = X2 / X1
Parameters
• L – distance sample - PONI
• rot1 – angle1
• rot2 – angle2
• rot3 – angle3
• pos1 – numpy array with distances in meter along dim1 from PONI (Y)
• pos2 – numpy array with distances in meter along dim2 from PONI (X)
• pos3 – numpy array with distances in meter along Sample->PONI (Z), positive behindthe detector
• wavelength – in meter to get q in nm-1
238 Chapter 6. pyFAI API
![Page 243: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/243.jpg)
pyFAI Documentation, Release 0.15.0a0
Returns ndarray of double with same shape and size as pos1
pyFAI.ext._geometry.calc_r(double L, double rot1, double rot2, double rot3, ndarray pos1,ndarray pos2, ndarray pos3=None)
Calculate the radius array (radial direction) in parallel
Parameters
• L – distance sample - PONI
• rot1 – angle1
• rot2 – angle2
• rot3 – angle3
• pos1 – numpy array with distances in meter along dim1 from PONI (Y)
• pos2 – numpy array with distances in meter along dim2 from PONI (X)
• pos3 – numpy array with distances in meter along Sample->PONI (Z), positive behindthe detector
Returns ndarray of double with same shape and size as pos1
pyFAI.ext._geometry.calc_rad_azim(double L, double poni1, double poni2, double rot1, dou-ble rot2, double rot3, ndarray pos1, ndarray pos2, ndar-ray pos3=None, space=‘2th’, wavelength=None)
Calculate the radial & azimutal position for each pixel from pos1, pos2, pos3.
Parameters
• L – distance sample - PONI
• poni1 – PONI coordinate along y axis
• poni2 – PONI coordinate along x axis
• rot1 – angle1
• rot2 – angle2
• rot3 – angle3
• pos1 – numpy array with distances in meter along dim1 from PONI (Y)
• pos2 – numpy array with distances in meter along dim2 from PONI (X)
• pos3 – numpy array with distances in meter along Sample->PONI (Z), positive behindthe detector
• space – can be “2th”, “q” or “r” for radial units. Azimuthal units are radians
Returns ndarray of double with same shape and size as pos1 + (2,),
Raise KeyError when space is bad ! ValueError when wavelength is missing
pyFAI.ext._geometry.calc_tth(double L, double rot1, double rot2, double rot3, ndarray pos1,ndarray pos2, ndarray pos3=None)
Calculate the 2theta array (radial angle) in parallel
Parameters
• L – distance sample - PONI
• rot1 – angle1
• rot2 – angle2
• rot3 – angle3
• pos1 – numpy array with distances in meter along dim1 from PONI (Y)
• pos2 – numpy array with distances in meter along dim2 from PONI (X)
6.24. ext.__init__ Module 239
![Page 244: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/244.jpg)
pyFAI Documentation, Release 0.15.0a0
• pos3 – numpy array with distances in meter along Sample->PONI (Z), positive behindthe detector
Returns ndarray of double with same shape and size as pos1
ext.histogram Module
Re-implementation of the numpy.histogram, optimized for azimuthal integration. Deprecated, will be replaced bysilx.math.histogramnd Re-implementation of numpy histograms using OpenMP
pyFAI.ext.histogram.histogram(ndarray pos, ndarray weights, int bins=100,bin_range=None, pixelSize_in_Pos=None, nthread=None,double empty=0.0, double normalization_factor=1.0)
Calculates histogram of pos weighted by weights
Parameters
• pos – 2Theta array
• weights – array with intensities
• bins – number of output bins
• pixelSize_in_Pos – size of a pixels in 2theta: DESACTIVATED
• nthread – OpenMP is disabled. unused
• empty – value given to empty bins
• normalization_factor – divide the result by this value
Returns 2theta, I, weighted histogram, raw histogram
pyFAI.ext.histogram.histogram2d(ndarray pos0, ndarray pos1, bins, ndarray weights,split=False, nthread=None, double empty=0.0, doublenormalization_factor=1.0)
Calculate 2D histogram of pos0,pos1 weighted by weights
Parameters
• pos0 – 2Theta array
• pos1 – Chi array
• weights – array with intensities
• bins – number of output bins int or 2-tuple of int
• split – pixel splitting is disabled in histogram
• nthread – maximum number of thread to use. By default: maximum available.
• empty – value given to empty bins
• normalization_factor – divide the result by this value
Returns I, edges0, edges1, weighted histogram(2D), unweighted histogram (2D)
One can also limit this with OMP_NUM_THREADS environment variable
ext.marchingsquares Module
The marchingsquares algorithm is used for calculating an iso-contour curve (displayed on the screen while cali-brating) but also to seed the points for the “massif” algoritm during recalib. Cythonized version of the marchingsquare function for “isocontour” plot
240 Chapter 6. pyFAI API
![Page 245: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/245.jpg)
pyFAI Documentation, Release 0.15.0a0
pyFAI.ext.marchingsquares.isocontour(img, isovalue=None, sorted=False)isocontour(img, isovalue=None)
Calculate the iso contours for the given 2D image. If isovalue is not given or None, a value between the minand max of the image is used.
Parameters
• img – 2D array representing the image
• isovalue – the value for which the iso_contour shall be calculated
• sorted – perform a sorting of the points to have them contiguous ?
Returns a pointset in which each two subsequent points form a line piece. This van be best visualized using“vv.plot(result, ls=’+’)”.
pyFAI.ext.marchingsquares.marching_squares(__Pyx_memviewslice img, double iso-value, __Pyx_memviewslice cellToEdge,__Pyx_memviewslice edgeToRelative-PosX, __Pyx_memviewslice edgeToRela-tivePosY)
pyFAI.ext.marchingsquares.sort_edges(edges)Reorder edges in such a way they become contiguous
ext.morphology Module
The morphology extension provides a couple of binary morphology operations on images. They are also imple-mented in scipy.ndimage in the general case, but not as fast. A few binary morphology operation
pyFAI.ext.morphology.binary_dilation(__Pyx_memviewslice image, float radius=1.0)Return fast binary morphological dilation of an image.
Morphological dilation sets a pixel at (i,j) to the maximum over all pixels in the neighborhood centered at(i,j). Dilation enlarges bright regions and shrinks dark regions.
:param image : ndarray :param radius: float :return: ndiamge
pyFAI.ext.morphology.binary_erosion(__Pyx_memviewslice image, float radius=1.0)Return fast binary morphological erosion of an image.
Morphological erosion sets a pixel at (i,j) to the minimum over all pixels in the neighborhood centered at(i,j). Erosion shrinks bright regions and enlarges dark regions.
:param image : ndarray :param radius: float :return: ndiamge
ext.reconstruct Module
Very simple inpainting module for reconstructing the missing part of an image (masked) to be able to use morecommon algorithms. Cython module to reconstruct the masked values of an image
pyFAI.ext.reconstruct.reconstruct(ndarray data, ndarray mask=None, dummy=None,delta_dummy=None)
reconstruct missing part of an image (tries to be continuous)
Parameters
• data – the input image
• mask – where data should be reconstructed.
• dummy – value of the dummy (masked out) data
• delta_dummy – precision for dummy values
Returns reconstructed image.
6.24. ext.__init__ Module 241
![Page 246: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/246.jpg)
pyFAI Documentation, Release 0.15.0a0
ext.relabel Module
Relabel regions, used to flag from largest regions to the smallest A module to relabel regions
pyFAI.ext.relabel.countThem(ndarray label, ndarray data, ndarray blured)Count
Parameters
• label – 2D array containing labeled zones
• data – 2D array containing the raw data
• blured – 2D array containing the blured data
Returns
2D arrays containing:
• count pixels in labeled zone: label == index).sum()
• max of data in that zone: data[label == index].max()
• max of blurred in that zone: blured[label == index].max()
• data-blurred where data is max.
ext.preproc Module
Contains a preprocessing function in charge of the dark-current subtraction, flat-field normalization, ... taking careof masked values and normalization.
pyFAI.ext.preproc.preproc(raw, dark=None, flat=None, solidangle=None, polariza-tion=None, absorption=None, mask=None, dummy=None,delta_dummy=None, float normalization_factor=1.0, empty=None,bool split_result=False, variance=None, dark_variance=None,bool poissonian=False)
Common preprocessing step for all
Parameters
• raw – raw value, as a numpy array, 1D or 2D
• mask – array non null where data should be ignored
• dummy – value of invalid data
• delta_dummy – precision for invalid data
• dark – array containing the value of the dark noise, to be subtracted
• flat – Array containing the flatfield image. It is also checked for dummies if relevant.
• solidangle – the value of the solid_angle. This processing may be performed duringthe rebinning instead. left for compatibility
• polarization – Correction for polarization of the incident beam
• absorption – Correction for absorption in the sensor volume
• normalization_factor – final value is divided by this
• empty – value to be given for empty bins
• variance – variance of the data
• dark_variance – variance of the dark
242 Chapter 6. pyFAI API
![Page 247: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/247.jpg)
pyFAI Documentation, Release 0.15.0a0
All calculation are performed in single precision floating point.
NaN are always considered as invalid
if neither empty nor dummy is provided, empty pixels are 0
ext._tree Module
The tree is used in file hierarchy tree for the diff_map graphical user interface.
class pyFAI.ext._tree.TreeItem(str label=None, TreeItem parent=None)Bases: object
Node of a tree ...
Each node contains:
•children: list
•parent: TreeItem parent
•label: str
•order: int
•type: str can be “dir”, “file”, “group” or “dataset”
•extra: any object
__init__x.__init__(...) initializes x; see help(type(x)) for signature
add_child(self, TreeItem child)
childrenchildren: list
extraextra: object
first(self)→ TreeItem
get(self, str label)→ TreeItem
has_child(self, str label)→ bool
labellabel: str
last(self)→ TreeItem
name
next(self)→ TreeItem
orderorder: ‘int’
parentparent: pyFAI.ext._tree.TreeItem
previous(self)→ TreeItem
size
sort(self)
typetype: str
update(self, TreeItem new_root)Add new children in tree
6.24. ext.__init__ Module 243
![Page 248: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/248.jpg)
pyFAI Documentation, Release 0.15.0a0
ext.watershed Module
Peak peaking via inverse watershed for connecting region of high intensity Inverse watershed for connectingregion of high intensity
class pyFAI.ext.watershed.BilinearBases: object
Bilinear interpolator for finding max.
Instance attribute defined in pxd file
cp_local_maxi(self, size_t x)→ size_t
data
f_cy(self, x)Function -f((y,x)) where f is a continuous function (y,x) are pixel coordinates pixels outside the imageare given an arbitrary high value to help the minimizer
Parameters x – 2-tuple of float
Returns Interpolated negative signal from the image
(negative for using minimizer to search for peaks)
height
local_maxi(self, x)Return the local maximum with sub-pixel refinement.
Sub-pixel refinement: Second order Taylor expansion of the function; first derivative is null
𝑑𝑒𝑙𝑡𝑎 = 𝑥− 𝑖 = −𝐼𝑛𝑣𝑒𝑟𝑠𝑒[𝐻𝑒𝑠𝑠𝑖𝑎𝑛].𝑔𝑟𝑎𝑑𝑖𝑒𝑛𝑡
If Hessian is singular or |𝑑𝑒𝑙𝑡𝑎| > 1: use a center of mass.
Parameters
• x – 2-tuple of integers
• w – half with of the window: 1 or 2 are advised
Returns 2-tuple of float with the nearest local maximum
maxi
mini
width
class pyFAI.ext.watershed.InverseWatershedBases: object
Idea:
•label all peaks
•define region around those peaks which raise always to this peak
•define the border of such region
•search for the pass between two peaks
•merge region with high pass between them
NAME = ‘Inverse watershed’
VERSION = ‘1.0’
__init__(self, data, thres=1.0)
Parameters data – 2d image as numpy array
244 Chapter 6. pyFAI API
![Page 249: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/249.jpg)
pyFAI Documentation, Release 0.15.0a0
init(self)
init_borders(self)
init_labels(self)
init_pass(self)
init_regions(self)
classmethod load(cls, fname)Load data from a HDF5 file
merge_intense(self, thres=1.0)Merge groups then (pass-mini)/(maxi-mini) >=thres
merge_singleton(self)merge single pixel region
merge_twins(self)Twins are two peak region which are best linked together: A -> B and B -> A
peaks_from_area(self, mask, Imin=None, keep=None, bool refine=True, float dmin=0.0,**kwarg)
Parameters
• mask – mask of data points valid
• Imin – Minimum intensity for a peak
• keep – Number of points to keep
• refine – refine sub-pixel position
• dmin – minimum distance from
save(self, fname)Save all regions into a HDF5 file
class pyFAI.ext.watershed.RegionBases: object
border
get_borders(self)
get_highest_pass(self)
get_index(self)
get_maxi(self)
get_mini(self)
get_neighbors(self)
get_pass_to(self)
get_size(self)
highest_pass
index
init_values(self, __Pyx_memviewslice flat)Initialize the values : maxi, mini and pass both height and so on :param flat: flat view on the data(intensity) :return: True if there is a problem and the region should be removed
maxi
merge(self, Region other)merge 2 regions
6.24. ext.__init__ Module 245
![Page 250: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/250.jpg)
pyFAI Documentation, Release 0.15.0a0
mini
neighbors
pass_to
peaks
size
246 Chapter 6. pyFAI API
![Page 251: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/251.jpg)
CHAPTER 7
Installation of Python Fast Azimuthal Integration library
Abstract
Installation procedure for all main operating systems
Hardware requirement
PyFAI has been tested on various hardware: i386, x86_64, PPC64le, ARM. The main constrain may be thememory requirement: 2GB of memory is a minimal requirement to run the tests. The program may run withless but “MemoryError” are expected (appearing sometimes as segmentation faults). As a consequence, a 64-bitsoperating system with enough memory is strongly advised.
Dependencies
PyFAI is a Python library which relies on the scientific stack (numpy, scipy, matplotlib)
• Python: version 2.7, 3.4, 3.5 and 3.6. Support for 2.6, 3.2 and 3.3 has been dropped in v0.12
• NumPy: version 1.4 or newer
• SciPy: version 0.7 or newer
• Matplotlib: verson 0.99 or newer
• FabIO: version 0.4 or newer
• h5py (to access HDF5 files)
• silx (version 0.5+ http://www.silx.org)
There are plenty of optional dependencies which will not prevent pyFAI from working by may impair perfor-mances or prevent tools from properly working:
• pyopencl (for GPU computing)
• fftw (for image analysis)
• pymca (for mask drawing)
247
![Page 252: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/252.jpg)
pyFAI Documentation, Release 0.15.0a0
• PyQt4 or PySide (for the graphical user interface)
Build dependencies:
In addition to the run dependencies, pyFAI needs a C compiler to build extensions.
C files are generated from cython source and distributed. The distributed version correspond to OpenMP version.Non-OpenMP version needs to be built from cython source code (especially on MacOSX). If you want to generateyour own C files, make sure your local Cython version is sufficiently recent (>0.20).
Building procedure
python setup.py buildpip install . --upgrade
There are few specific options to setup.py:
• --no-cython: Prevent Cython (even if present) to re-generate the C source code. Use the one providedby the development team.
• --no-openmp: Recompiles the Cython code without OpenMP support (default under MacOSX).
• --openmp: Recompiles the Cython code with OpenMP support (Default under Windows and Linux).
• --with-testimages: build the source distribution including all test images. Download 200MB of testimages to create a self consistent tar-ball.
Detailed installation procedure on different operating systems
Installation procedure on Linux
We cover first Debian-like distribution, then a generic recipie for all other version is given.
Installation procedure on Debian/Ubuntu
PyFAI has been designed and originally developed on Ubuntu 10.04 and debian6. Now, the pyFAI library isincluded into debian7, 8, 9 and any recent Ubuntu and Mint distribution. To install the package provided by thedistribution, use:
sudo apt-get install pyfai
The issue with distribution based installation is the obsolescence of the version available.
Debian 7 and Ubuntu 12.04
To build a more recent version, pyFAI provides you a small scripts which builds a debian package and installs it.It relies on stdeb and provides a single package with everything inside. You will be prompted for your passwordto gain root access in order to be able to install the freshly built package.
sudo apt-get install python-stdeb cython python-fabiowget https://github.com/silx-kit/pyFAI/archive/master.zipunzip master.zipcd pyFAI-master./build-deb7.sh
248 Chapter 7. Installation of Python Fast Azimuthal Integration library
![Page 253: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/253.jpg)
pyFAI Documentation, Release 0.15.0a0
Debian 8, 9 and newer
Thanks to the work of Frédéric-Emmanuel Picca, the debian package of pyFAI provides a pretty good templatewhich allows continuous builds.
From silx repository
You can automatically install the latest nightly built of pyFAI with:
wget http://www.silx.org/pub/debian/silx.listwget http://www.silx.org/pub/debian/silx.prefsudo mv silx.list /etc/apt/sources.list.d/sudo mv silx.pref /etc/apt/preferences.d/sudo apt-get updatesudo apt-get install pyfai
Nota: The nightly built packages are not signed, hence you will be prompted to install non-signed packages.
Build from sources
One can also built from sources:
sudo apt-get install cython cython-dbg cython3 cython3-dbg debhelper dh-python \python-all-dev python-all-dbg python-fabio python-fabio-dbg python-fftw python-→˓h5py \python-lxml python-lxml-dbg python-matplotlib python-matplotlib-dbg python-numpy\python-numpy-dbg python-qt4 python-qt4-dbg python-scipy python-scipy-dbg python-→˓sphinx \python-sphinxcontrib.programoutput python-tk python-tk-dbg python3-all-dev python3-→˓all-dbg \python3-fabio python3-fabio-dbg python3-lxml python3-lxml-dbg python3-matplotlib \python3-matplotlib-dbg python3-numpy python3-numpy-dbg python3-pyqt4 python3-pyqt4-→˓dbg \python3-scipy python3-scipy-dbg python3-sphinx python3-sphinxcontrib.programoutput→˓\python3-tk python3-tk-dbg python-silx python3-silxwget https://github.com/silx-kit/pyFAI/archive/master.zipunzip master.zipcd pyFAI-master./build-deb8.sh
The first line is really long and defines all the dependence tree for building debian package, including debug anddocumentation. The build procedure last for a few minutes and you will be prompted for your password in orderto install the freshly built packages. The deb-*files, available in the *package directory are backports for yourlocal installation.
Installation procedure on other linux distibution
If your distribution does not provide you pyFAI packages, using the PIP way is advised, via wheels packages.First install pip and wheel:
sudo pip install pyFAI
Or you can install pyFAI from the sources:
wget https://github.com/silx-kit/pyFAI/archive/master.zipunzip master.zipcd pyFAI-master
7.6. Detailed installation procedure on different operating systems 249
![Page 254: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/254.jpg)
pyFAI Documentation, Release 0.15.0a0
python setup.py build testsudo pip install . --upgrade
Nota: The usage of “python setup.py install” is now deprecated. It causes much more trouble as there is noinstalled file tracking, hence no way to de-install properly the package.
Installation procedure on MacOSX
Using PIP
To install pyFAI on an Apple computer you will need a scientific Python stack. MacOSX provides by defaultPython2.7 with Numpy which is a good basis.
sudo pip install matplotlib --upgradesudo pip install scipy --upgradesudo pip install fabio --upgradesudo pip install h5py --upgradesudo pip install cython --upgradesudo pip install silx --upgradesudo pip install pyFAI --upgrade
If you get an error about the local “UTF-8”, try to:
export LC_ALL=C
Before the installation.
Installation from sources
Get the sources from Github:
wget https://github.com/silx-kit/pyFAI/archive/master.zipunzip master.zipcd pyFAI-master
About OpenMP
OpenMP is a way to write multi-threaded code, running on multiple processors simultaneously. PyFAI makesheavy use of OpenMP, but there is an issue with recent versions of MacOSX (>v10.6) where the default compilerof Apple, Xcode, dropped the support for OpenMP.
There are two ways to compile pyFAI on MacOSX:
• Using Xcode and de-activating OpenMP in pyFAI
• Using another compiler which supports OpenMP
Using Xcode
To build pyFAI from sources, a C-compiler is needed. On an Apple computer, the default compiler is Xcode, and itis available for free on the AppStore. As pyFAI has by default OpenMP activated, and it needs to be de-activated,one needs to regenerate all Cython files without OpenMP.
sudo pip install cython --upgraderm pyFAI/ext/*.cpython setup.py build --force-cython --no-openmp
250 Chapter 7. Installation of Python Fast Azimuthal Integration library
![Page 255: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/255.jpg)
pyFAI Documentation, Release 0.15.0a0
python setup.py bdist_wheelsudo pip install --find-links=dist/ --pre --no-index --upgrade pyFAI
Using gcc or clang
If you want to keep the OpenMP feature (which makes the processing slightly faster), the alternative is to installanother compiler like gcc or clang on your Apple computer. As gcc & clang support OpenMP, there is no need tore-generate the cython files.
CC=gcc python setup.py build --openmppython setup.py bdist_wheelsudo pip install --find-links=dist/ --pre --no-index --upgrade pyFAI
Nota: The usage of “python setup.py install” is now deprecated. It causes much more trouble as there is noinstalled file tracking, hence no way to de-install properly a package.
Installation procedure on Windows
PyFAI is a Python library. Even if you are only interested in some tool like pyFAI-calib or pyFAI-integrate, youneed to install the complete library (for now). This is usually performed in 3 steps:
1. install Python,
2. install the scientific Python stack
3. install pyFAI itself.
Get Python
Unlike on Unix computers, Python is not available by default on Windows computers. We recommend you toinstall the 64 bit version of Python, preferably the latest 64 bits version from the 3.6 series. But Python 2.7, 3.4and 3.5 are also very good candidates. Python 2.6, 3.2 and 3.3 are no more supported since pyFAI v0.12.
The 64 bits version is strongly advised if your hardware and operating system supports it, as the 32 bits versionsis limited to 2 GB of memory, hence unable to treat large images (like 4096 x 4096). The test suite is not passingon Windows 32 bits due to the limited amount of memory available to the Python process, nevertheless, pyFAI isrunning on Windows 32 bits (but not as well).
Alternative Scientific Python stacks exists, like Enthought Python Distribution , Canopy, Anaconda, PythonXYor WinPython. They all offer most of the scientific packages already installed which makes the installation ofdependencies much easier. On the other hand, they all offer different packaging system and we cannot support allof them. Moreover, distribution from Enthought and Continuum are not free so you should be able to get supportfrom those companies.
Nota: any flavor of those Python distribution is probably incompatible with any other due to change in compileror Python compilation options. Mixing them is really looking for trouble, hence strongly discouraged. If you wantan advice on which scientific python distribution for Windows to use, I would recommend WinPython.
Install PIP
PIP is the package management system for Python, it connects to the Python Package Index, download and installsoftware packages from there.
PIP has revolutionize the way Python libraries are installed as it is able to select the right build for your system,or compile them from the sources, which could be extremely tricky otherwise. If you installed python 2.7.10, 3.4or newer, PIP is already installed. If pip is not yet installed on your system, download get_pip.py and run it:
7.6. Detailed installation procedure on different operating systems 251
![Page 256: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/256.jpg)
pyFAI Documentation, Release 0.15.0a0
python get-pip.py
Assuming python.exe is already in your PATH.
Nota: Because PIP connects to the network, the http_proxy and https_proxy environment variable may need to beset-up properly. At ESRF, please get in contact with the hotline (24-24) to retrive those information.
Install the scientific stack
The strict dependencies for pyFAI are:
• NumPy
• SciPy
• matplotlib
• FabIO
• h5py
• silx
Recommended dependencies are:
• cython
• h5py
• pyopencl
• PyQt5
• pymca
• rfoo
• pyfftw3
• lxml
Using PIP
Most of the dependencies are available via PIP:
pip install numpy --upgradepip install scipy --upgradepip install matplotlib --upgradepip install PyQt5 --upgradepip install fabio --upgradepip install silx --upgrade
Note that numpy/scipy/matplotlib are already installed in most “Scientific Python distribution”
If one of the dependency is not available as a Wheel (i.e. binary package) but only as a source package, a compilerwill be required. In this case, see the next paragraph. The generalization of Wheel packages should help and theinstallation of binary modules should become easier.
Nota: This requires a network access and correct proxy settings. At ESRF, please get in contact with the hotline(24-24) to retrive those information.
set http_proxy=http://proxy.site.com:3128set https_proxy=http://proxy.site.com:3128
252 Chapter 7. Installation of Python Fast Azimuthal Integration library
![Page 257: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/257.jpg)
pyFAI Documentation, Release 0.15.0a0
Using Christoph Gohlke repository
Christoph Gohlke is a researcher at Laboratory for Fluorescence Dynamics, University of California, Irvine. Heis maintaining a large repository Python extension (actually, all we need :) for Windows. Check twice the Pythonversion and the Windows version (win32 or win_amd64) before downloading.
Moreover the libraries he provides are linked against the MKL library from Intel which makes his packages fasterthen what you would get by simply recompiling them.
Christoph now provides packages as wheels. To install them, download the wheels and use PIP:
pip install numpy*.whl
Alternatively, you can use the wheelhouse of the silx project:
pip install --trusted-host www.silx.org --find-links http://www.silx.org/pub/→˓wheelhouse/ numpy scipy matplotlib fabio PyQt5
Install pyFAI via PIP
The latest stable release of pyFAI should also be PIP-installable (starting at version 0.10.3):
pip install pyFAI --upgrade
Install pyFAI from sources
The sources of pyFAI are available at https://github.com/silx-kit/pyFAI/releases the development is performed onhttps://github.com/kif/pyFAI
In addition to the Python interpreter, you will need the C compiler compatible with your Python interpreter, forexample you can find the one for Python2.7 at: http://aka.ms/vcpython27
To upgrade the C-code in pyFAI, one needs in addition Cython:
pip install cython --upgradepython setup.py bdist_wheelpip install --pre --no-index --find-links dist/ pyFAI
Troubleshooting
This section contains some tips on windows.
Side-by-side error
When starting pyFAI you get a side-by-side error like:
ImportError: DLL load failed: The application has failed to start because itsside-by-side configuration is incorrect. Please see the application event log oruse the command-line sxstrace.exe tool for more detail.
This means you are using a version of pyFAI which was compiled using the MSVC compiler (maybe not on yourcomputer) but the Microsoft Visual C++ Redistributable Package is missing. For Python2.7, 64bits the missingDLL can be downloaded from:
http://www.microsoft.com/en-us/download/confirmation.aspx?id=2092
7.6. Detailed installation procedure on different operating systems 253
![Page 258: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/258.jpg)
pyFAI Documentation, Release 0.15.0a0
Test suites
PyFAI comes with a test suite to ensure all core functionalities are working as expected and numerical results arecorrect:
python setup.py build test
Nota: to run the test, an internet connection is needed as 200MB of test images need to be download. You mayhave to set the environment variable http_proxy and https_proxy according to the networking environment you arein. Specifically at ESRF, please phone the hotline at 24-24 to get those information.
Environment variables
PyFAI can use a certain number of environment variable to modify its default behavior:
• PYFAI_OPENCL: set to “0” to disable the use of OpenCL
• PYFAI_DATA: path with gui, calibrant, ...
• PYFAI_TESTIMAGES: path wit test images (if absent, they get downloaded from the internet)
254 Chapter 7. Installation of Python Fast Azimuthal Integration library
![Page 259: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/259.jpg)
CHAPTER 8
PyFAI Ecosystem
Software pyFAI is relying on
PyFAI is relying on the full Python scientific stack which includes [NumPy], [SciPy], [Matplotlib], [PyOpenCL]but also on some ESRF-developped code:
FabIO
PyFAI is using FabIO everywhere access to a 2D images is needed. The fabio_viewer is also a lightweightconvenient viewer for diffraction images. It has been described in doi:10.1107/S0021889813000150
PyMca
The X-ray Fluorescence Toolkit provides convenient tools for HDF5 file browsing and mask drawing. It has beendescribed in doi:10.1016/j.sab.2006.12.002
Silx
The silx toolkit is currently onging development. Future releases of pyFAI will use its input/output and graphicalvisualization capabilities
Program using pyFAI as a library
Bubble
Client-server program to perform azimuthal integration online. Developed for the SNBL and Dubble beamlinesby Vadim DIADKIN and available from this mercurial repository.
255
![Page 260: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/260.jpg)
pyFAI Documentation, Release 0.15.0a0
Dahu
Dahu is a lightweight plugin based framework available from this git repository. Lighter then EDNA, it is techni-cally a JSON-RPC server over Tango. Used on TRUSAXS beamline at ESRF (ID02), ID15 and ID31, dahu usespyFAI to process data up to the kHz range.
Dioptas
Graphical user interface for high-pressure diffraction, developed at the APS synchrotron by C. Prescher and de-scribed in: doi:10.1080/08957959.2015.1059835
The amount of data collected during synchrotron X-ray diffraction (XRD) experiments is constantly increas-ing. Most of the time, the data are collected with image detectors, which necessitates the use of image reduc-tion/integration routines to extract structural information from measured XRD patterns. This step turns out to be abottleneck in the data processing procedure due to a lack of suitable software packages. In particular, fast-runningsynchrotron experiments require online data reduction and analysis in real time so that experimental parameterscan be adjusted interactively. Dioptas is a Python-based program for on-the-fly data processing and exploration oftwo-dimensional X-ray diffraction area detector data, specifically designed for the large amount of data collectedat XRD beamlines at synchrotrons. Its fast data reduction algorithm and graphical data exploration capabilitiesmake it ideal for online data processing during XRD experiments and batch post-processing of large numbers ofimages.
Dpdak
Graphical user interface for small angle diffusion, developed at the Petra III synchrotron by G. Benecke andco-workers and described in doi:10.1107/S1600576714019773
X-ray scattering experiments at synchrotron sources are characterized by large and constantly increasing amountsof data. The great number of files generated during a synchrotron experiment is often a limiting factor in theanalysis of the data, since appropriate software is rarely available to perform fast and tailored data processing.Furthermore, it is often necessary to perform online data reduction and analysis during the experiment in order tointeractively optimize experimental design. This article presents an open-source software package developed toprocess large amounts of data from synchrotron scattering experiments. These data reduction processes involvecalibration and correction of raw data, one- or two-dimensional integration, as well as fitting and further analysisof the data, including the extraction of certain parameters. The software, DPDAK (directly programmable dataanalysis kit), is based on a plug-in structure and allows individual extension in accordance with the requirementsof the user. The article demonstrates the use of DPDAK for on- and offline analysis of scanning small-angle X-rayscattering (SAXS) data on biological samples and microfluidic systems, as well as for a comprehensive analysisof grazing-incidence SAXS data. In addition to a comparison with existing software packages, the structure ofDPDAK and the possibilities and limitations are discussed.
EDNA
EDNA is a framework for developing plugin-based applications especially for online data analysis in the X-rayexperiments field (http://edna-site.org) A EDNA data analysis server is using pyFAI as an integration engine (onthe GPU) on the ESRF BioSaxs beamline, BM29. The server is running 24x7 with a processing frequency from0.1 to 10 Hz.
LImA
The Library for Image Acquisition, developped at the European synchrotron is used worldwide to control anytypes of cameras. A pyFAI plugin has been written to integrate images on the fly without saving them. (no moretested).
256 Chapter 8. PyFAI Ecosystem
![Page 261: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/261.jpg)
pyFAI Documentation, Release 0.15.0a0
NanoPeakCell
NanoPeakCell (NPC) is a python-software intended to pre-process your serial crystallography raw-data into ready-to-be-inedexed images with CrystFEL, cctbx.xfel and nXDS. NPC is able to process data recorded at SACLA andLCLS XFELS, as well as data recorded at any synchrotron beamline. A graphical interface is deployed to visualizeyour raw and pre-processed data.
Developed at IBS (Grenoble) by N. Coquelle
pygix
A Python library for reduction of 2D grazing-incidence X-ray scattering data developped at ESRF (ID13) byThomas DANE.
Grazing-incidence X-ray scattering techniques (GISAXS, GIWAXS/GID) allow the study of thin films on surfacesthat would otherwise be unmeasurable in standard transmission geometry experiments. The fixed incident X-rayangle gives rise to a distortion in the diffraction patterns, which is extreme at wide-angles. The pygix libraryprovides routines for projecting 2D detector images into corrected reciprocal space maps, radial transformationsand line profile extraction using pyFAI’s regrouping functions.
PySAXS
Python for Small Angle X-ray Scattering data acquisition, treatment and computation of model SAXS intensities.
Developed at CEA Saclay by O. Taché and available on PyPI.
Xi-cam
Xi-cam is developed by Ronald Pandolfi, Dinesh Kumar, Singanallur Venkatakrishnan and Alexander Hexemer atALS.
Xi-cam aims to provide a community driven platform for multimodal analysis in synchrotron science. The plat-form core provides a robust plugin infrastructure for extensibility, allowing continuing development to simply addfurther functionality. Current modules include tools for characterization with (GI)SAXS, Tomography, and XAS.This will continue to serve as a development base as algorithms for multimodal analysis develop.
Seamless remote data access, visualization and analysis are key elements of Xi-CAM, and will become critical tosynchrotron data infrastructure as expectations for future data volume and acquisition rates rise with continuouslyincreasing throughputs. The highly interactive design elements of Xi-cam will similarly support a generation ofusers which depend on immediate data quality feedback during high-throughput or burst acquisition modes.
xPDFsuite
Developed by the Billinge Group, this commercial software is described in arXiv 1402.3163 (2014)
xPDFsuite is an application that facilitates the workflow of atomic pair distribution function analysis of x-raydiffraction measurements from complex materials. It is specially designed to help the scientist visualize, handleand process large numbers of datasets that is common when working with high throughput modern synchrotronsources. It has a full-featured interactive graphical user interface (GUI) with 3D and 3D graphics for plotting dataand it incorporates a number of powerful packages for integrating 2D powder diffraction images, analyzing thecurves to obtain PDFs and then tools for assessing the data and modeling it. It is available from diffpy.org.
8.2. Program using pyFAI as a library 257
![Page 262: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/262.jpg)
pyFAI Documentation, Release 0.15.0a0
258 Chapter 8. PyFAI Ecosystem
![Page 263: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/263.jpg)
CHAPTER 9
Project
PyFAI is a library to deal with diffraction images for data reduction. This chapter describes the project from thecomputer engineering point of view.
PyFAI is an open source project licensed under the MIT license (previously under GPL) mainly written in Python(v2.7, 3.4 or newer). It is managed by the Silx team and is heavily relying on the Python scientific ecosystem:numpy, scipy and matplotlib. It provides high performances image treatment thanks to Cython and OpenCL... butonly a C-compiler is needed to build it.
Programming language
PyFAI is a Python project but uses many programming languages:
• 23000 lines of Python (plus 5000 for the test)
• 8000 lines of Cython which are converted into ... C (about half a million lines)
• 5000 lines of OpenCL kernels
The OpenCL code has been tested using:
• Nvidia OpenCL v1.1 and v1.2 on Linux, Windows (GPU device)
• Intel OpenCL v1.2 on Linux and Windows (CPU and ACC (Phi) devices)
• AMD OpenCL v1.2 on Linux and Windows (CPU and GPU device)
• Apple OpenCL v1.2 on MacOSX (CPU and GPU)
• Beignet OpenCL v1.2 on Linux (GPU device)
• Pocl OpenCL v1.2 on Linux (CPU device)
Repository
The project is hosted on GitHub: https://github.com/silx-kit/pyFAI
Which provides the issue tracker in addition to Git hosting. Collaboration is done via Pull-Requests in github’sweb interface:
259
![Page 264: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/264.jpg)
pyFAI Documentation, Release 0.15.0a0
Everybody is welcome to fork the project and adapt it to his own needs: CEA-Saclay, Synchrotrons Soleil, Desyand APS have already done so. Collaboration is encouraged and new developments can be submitted and mergedinto the main branch via pull-requests.
Getting help
A mailing list, [email protected], is publicly available. I t is the best place to ask your questions: the author andmany advanced users are there and willing to help you. To subscribe to this mailing list, send an email to [email protected].
On this mailing list, you will have information about release of the software, new features available and meetexperts to help you solve issues related to azimuthal integration and diffraction in general. It also provides aknowledge-base of most frequently asked question which needs to be integrated into this documentation.
The volume of email on the list remains low, so you can subscribe without being too much spammed. As themailing list is archived, and can be consulted at: http://www.edna-site.org/lurker, you can also check the volumeof the list.
If you think you are facing a bug, the best is to create a new issue on the GitHub page (you will need a GitHubaccount for that).
Direct contact with authors is discouraged: pyFAI is open source software that we develop to aid the researchcommunity in doing what they do best. While we do enjoy doing this, we would not be able to dream of spendingnearly as much time with pyFAI as we do if it wasn’t for your support. Interest of the scientific community (viaa lively mailing list) and citation in scientific publication for our software is one of the main criterion for ESRFmanagement when deciding if they should continue funding development.
Run dependencies
• Python version 2.7, 3.4, 3.5, 3.6
• NumPy
• SciPy
• Matplotlib
• FabIO
• h5py
• pyopencl (optional)
• PyQt4 or PySide (for the graphical user interface)
• Silx
Build dependencies
In addition to the run dependencies, pyFAI needs a C compiler.
There is an issue with MacOS (v10.8 onwards) where the default compiler (Xcode5 or newer) dropped the supportfor OpenMP. On this platform pyFAI will enforce the generation of C-files from Cython sources (making Cythona build-dependency on MacOS) without support of OpenMP (options: –no-openmp –force-cython). On OSX, analternative is to install a recent version of GCC (>=4.2) and to use it for compiling pyFAI. The options to be usedthen are * –force-cython –openmp*.
Otherwise, C files are which are provided with pyFAI sources are directly useable and Cython is only needed fordeveloping new binary modules. If you want to generate your own C files, make sure your local Cython version isrecent enough (v0.21 and newer), unless your Cython files will not be translated to C, nor used.
260 Chapter 9. Project
![Page 265: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/265.jpg)
pyFAI Documentation, Release 0.15.0a0
Building procedure
As most of the Python projects:
python setup.py build bdist_wheelpip install dist/pyFAI-0.14.0*.whl --upgrade
There are few specific options to setup.py:
• –no-cython: do not use cython (even if present) and use the C source code provided by the developmentteam
• –force-cython: enforce the regeneration of all C-files from cython sources
• –no-openmp: if you compiler lacks OpenMP support, like Xcode on MacOS.
• –openmp: enforce the use of OpenMP.
• –with-testimages: build the source distribution including all test images. Downloads 200MB of test imagesto create a self consistent tar-ball.
Test suites
To test the installed version of pyFAI:
python run_test.py
or from python:
import pyFAIpyFAI.tests()
Some Warning messages are normal as the test procedure also tests corner cases.
To run the test an internet connection is needed as 200MB of test images will bedownloaded.
Setting the environment variable http_proxy can be necessary (depending on your network):
export http_proxy=http://proxy.site.org:3128
Especially at ESRF, the configuration of the network proxy can be obtained by asking at the helpdesk:[email protected]
To test the development version (built but not yet installed):
python setup.py build test
or
python setup.py buildpython run_test.py -i
PyFAI comes with 40 test-suites (338 tests in total) representing a coverage of 60%. This ensures both nonregression over time and ease the distribution under different platforms: pyFAI runs under Linux, MacOSX andWindows (in each case in 32 and 64 bits). Test may not pass on computer featuring less than 2GB of memory or32 bit architectures.
Note:: The test coverage tool does not count lines of Cython, nor those of OpenCL. Anyway test coverage is atool for developers about possible weaknesses of their code and not a management indicator.
9.6. Building procedure 261
![Page 266: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/266.jpg)
pyFAI Documentation, Release 0.15.0a0
Test coverage report for pyFAI
Measured on pyFAI version 0.14.0, 20/07/2017
Table 9.1: Test suite coverage
Name Stmts Exec Cover__init__.py 36 20 55.6 %_version.py 41 39 95.1 %app/__init__.py 0 0 0.0 %app/average.py 178 56 31.5 %app/benchmark.py 54 36 66.7 %app/calib.py 30 22 73.3 %app/check_calib.py 30 23 76.7 %app/detector2nexus.py 82 38 46.3 %app/diff_map.py 30 18 60.0 %app/diff_tomo.py 111 56 50.5 %app/drawmask.py 139 44 31.7 %app/eiger_mask.py 56 32 57.1 %app/integrate.py 142 93 65.5 %app/mx_calibrate.py 28 19 67.9 %app/recalib.py 32 22 68.8 %app/saxs.py 80 45 56.2 %app/waxs.py 88 48 54.5 %average.py 526 390 74.1 %azimuthalIntegrator.py 1338 1019 76.2 %benchmark/__init__.py 522 80 15.3 %blob_detection.py 504 194 38.5 %calibrant.py 367 289 78.7 %calibration.py 1530 345 22.5 %containers.py 109 105 96.3 %control_points.py 344 57 16.6 %decorators.py 33 27 81.8 %detectors.py 1409 1103 78.3 %diffmap.py 331 98 29.6 %directories.py 34 23 67.6 %distortion.py 558 167 29.9 %ext/__init__.py 0 0 0.0 %geometry.py 1006 796 79.1 %geometryRefinement.py 515 207 40.2 %goniometer.py 287 146 50.9 %gui/__init__.py 4 4 100.0 %gui/matplotlib.py 24 17 70.8 %gui/qt.py 100 36 36.0 %gui/utils.py 34 14 41.2 %integrate_widget.py 456 268 58.8 %io.py 551 306 55.5 %massif.py 201 132 65.7 %multi_geometry.py 138 99 71.7 %opencl/__init__.py 13 13 100.0 %opencl/azim_csr.py 193 158 81.9 %opencl/azim_hist.py 269 191 71.0 %opencl/azim_lut.py 178 145 81.5 %opencl/common.py 283 201 71.0 %opencl/preproc.py 192 137 71.4 %opencl/processing.py 119 95 79.8 %
Continued on next page
262 Chapter 9. Project
![Page 267: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/267.jpg)
pyFAI Documentation, Release 0.15.0a0
Table 9.1 – continued from previous pageName Stmts Exec Cover
opencl/sort.py 259 207 79.9 %opencl/utils.py 32 21 65.6 %peak_picker.py 771 202 26.2 %preproc.py 96 75 78.1 %spline.py 432 165 38.2 %units.py 85 81 95.3 %utils/__init__.py 462 283 61.3 %utils/bayes.py 93 60 64.5 %utils/ellipse.py 40 37 92.5 %utils/shell.py 44 41 93.2 %utils/stringutil.py 25 24 96.0 %worker.py 363 197 54.3 %
pyFAI total 16027 8866 55.3 %
Continuous integration
This software engineering practice consists in merging all developer working copies to a shared mainline severaltimes a day and build the whole project for multiple targets.
On Debian 8 - Jessie
Continuous integration is made by a home-made scripts which checks out the latest release and builds and runsthe test every night. Nightly builds are available for debian8-64 bits. To install them:
sudo apt-get updatesudo apt-get install pyfai
You have to accept non-signed packages because they are automatically built.
In addition some “cloud-based” tools are used to ensure a larger coverage of operating systems/environment. Theyrely on a “local wheelhouse”.
Those wheels are optimized for Travis-CI, AppVeyor and ReadTheDocs, using them is not recommended as yourPython configuration may differ (and those libraries could even crash your system).
Linux
Travis provides continuous integration on Linux, 64 bits computer with Python 2.7, 3.4 and 3.5.
The builds cannot yet be retrieved with Travis-CI, but manylinux-wheels are on the radar.
AppVeyor
AppVeyor provides continuous integration on Windows, 64 bits computer with Python 2.7 and 3.4. Successfulbuilds provide installers for pyFAI as wheels and msi, they are anonymously available as artifacts. Due to thelimitation of AppVeyor’s build system, those installers have openMP disabled.
9.8. Continuous integration 263
![Page 268: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/268.jpg)
pyFAI Documentation, Release 0.15.0a0
List of contributors in code
$ git log --pretty='%aN##%s' | grep -v 'Merge pull' | grep -Po '^[^#]+' | sort |→˓uniq -c | sort -rn
As of 07/2017:
• Jérôme Kieffer (ESRF)
• Valentin Valls (ESRF)
• Frédéric-Emmanuel Picca (Soleil)
• Aurore Deschildre (ESRF)
• Giannis Ashiotis (ESRF)
• Dimitrios Karkoulis (ESRF)
• Jon Wright (ESRF)
• Zubair Nawaz (Sesame)
• Dodogerstlin @github
• Vadim Dyadkin (ESRF/SNBL)
• Gunthard Benecke (Desy)
• Gero Flucke (Desy)
• Christopher J. Wright (Columbia University)
• Sigmund Neher (GWDG)
• Wout De Nolf (ESRF)
• Bertrand Faure (Xenocs)
• Thomas Vincent (ESRF)
• Amund Hov (ESRF)
List of other contributors (ideas or code)
• Peter Boesecke (geometry)
• Manuel Sanchez del Rio (histogramming)
• Armando Solé (masking widget + PyMca plugin)
• Sebastien Petitdemange (Lima plugin)
List of supporters
• LinkSCEEM project: porting to OpenCL
• ESRF ID11: Provided manpower in 2012 and 2013 and beamtime
• ESRF ID13: Provided manpower in 2012, 2013, 2014, 2015, 2016 and beamtime
• ESRF ID29: provided manpower in 2013 (MX-calibrate)
• ESRF ID02: provided manpower 2014, 2016
• ESRF ID15: provide manpower 2015, 2016, 2017
• ESRF ID21: provide manpower 2015, 2016
264 Chapter 9. Project
![Page 269: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/269.jpg)
pyFAI Documentation, Release 0.15.0a0
• ESRF ID31: provide manpower 2016, 2017
9.11. List of supporters 265
![Page 270: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/270.jpg)
pyFAI Documentation, Release 0.15.0a0
266 Chapter 9. Project
![Page 271: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/271.jpg)
CHAPTER 10
ChangeLog of Versions
0.14.0: 20/07/2017
• Graphical user interface for calibration (pyFAI-calib2)
• Goniometer calibration tools and multi-geometry enhancements
• Integration scripts and averaging scripts are now able to normalize the data from monitors found in theheader.
• Propagate metadata information as part of the integrated data
• Common pre-processing factorization on Python, Cython and OpenCL
• Test clean up and acceleration (avoid tests on too large images)
• Many new tutorials http://pyfai.readthedocs.io/en/latest/usage/tutorial/index.html
• New averaging / integration methods: - Azimuthal median filtering - Azimuthal trimmed mean - sigma-clipping on azimuthal angle - Radial averaging
• Diffraction image inpainting to fill-up the gaps with plausible values.
• This release correspond to 572 commits
• Change of license: now all pyFAI is MIT license.
0.13.0: 01/12/2016
• Global improvement of tests, packaging, code quality, documentation and project tools
• Scripts
– Add support for multiframe formats on pyFAI-average
– Add support for monitoring correction from header file (on pyFAI-average)
– Add progressbar in the shell (on pyFAI-average and pyFAI-integrate)
– Script drawMask_pymca is renamed into pyFAI-drawmask
– Rework of the drawmask GUI using silx
267
![Page 272: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/272.jpg)
pyFAI Documentation, Release 0.15.0a0
– pyFAI-drawmask do not have anymore hard dependency on PyMCA
– pyFAI-integrate can now be used without qt dependency (–no-gui)
– Fix the script to support both Python 2 and 3 (pyFAI-calib, pyFAI-benchmark)
– Fix selection of units on diff-map (the user selection was not propagated)
• For users
– More source code in MIT license
– Update name and specification for cameras
– Add cameras: Eiger500k, RaspberryPi5M, RaspberryPi8M
– Fix Xpad S540 flat detector geometry
– Fix definition of CeO2 calibrant
– Add mask and flat on multi-geometry
– Fix solid angle of the multi-geometry
– Fix geometry processing for custom output space
– Fix normalization factor and variance
– Add support for Qt5
– Add support for Debian 9 packaging
• For developers
– Create common preprocessing for distortion correction
– Create common image preprocessing using Cython (NaN filter, flatfield, dark, polarisation)
– Refactoring of units module. It allows to register custom units.
– Worker can now use Writer
– Worker polarization argument is renamed into polarization_factor
– Remove the dependency from python-fftw3, use numpy instead
– Remove QtWebKit dependency
– Fix un-correction of images using sparse matrix from scipy
0.12.0: 06/06/2016
• Continuous integration on linux, windows using Python 2.7 and 3.4+
• Drop support of Python 2.6, 3.2, 3.3 and debian6 packaging
• New radial output units: Reciprocal spacing squared and log(q) ID02
• GPU accelerate version of ai.separate (Bragg & amorphous) ID13
• Quantile filtering in pyFAI-average ID02
• New graphical application for diffraction imaging ID21
• Migrate to a common structure with silx (reorganize tests, benchmarks, ...)
• Extensions (binary sub-modules) have all been moved to ext directory
• Many improvements multigeometry integrators
• Compatibility with the copy module (copy.deepcopy) for azimuthal integrator ID02
• Distortion correction works also for non-contiguous detectors
268 Chapter 10. ChangeLog of Versions
![Page 273: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/273.jpg)
pyFAI Documentation, Release 0.15.0a0
• Update documentation and provide advanced tutorials:
– Introduction to pyFAI using the jupyter notebook
– detector calibration ID15, BM02
– Correction of detector distortion, examples of pixel detectors.
– calibrant calculation ID30
– error handling ID02, BM29
• pyFAI-integrate can now be used with or without GUI
• Many new detectors (ADSC, Pilatus CdTe, Apex II, Pixium):
– support for non-flat/curved detectors (Aarhus)
– non-contiguous detectors (WOS Xpad)
• Include tests and benchmarking tools as part of the library
• Better testing.
0.11.0: 07/2015
• All calibrant from NIST are now available, + Nickel, Aluminum, ... with bibliographic references
• The Cell class helps defining new calibrants.
• OpenCL Bitonic sort (to be integrated into Bragg/Amorphous separation)
• Calib is available from the Python interface (procedural API), not only from the shell script.
• Many new options in calib for reset/assign/delete/validate/validate2/chiplot.
– reset: set the detector, orthogonal, centered and at 10cm
– assign: checks the assignment of groups of points to rings
– delete: remove a group of peaks
– validate: autocorrelation of images: error on the center
– validate2: autocorrelation of patterns at 180° apart: error on the center function of chi
– chiplot: assesses the quality of control points of one/multiple rings.
• Fix the regression of the initial guess in calib (Thanks Jon Wright)
• New peak picking algorithm named “watershed” and based on inverse watershed for ridge recognition
• start factorizing cython regridding engines (work ongoing)
• Add “–poni” option for pyFAI-calib (Thanks Vadim Dyakin)
• Improved “guess_binning”, especially for Perkin Elmer flat panel detectors.
• Support for non planar detectors like Curved Imaging plate developped at Aarhus
• Support for Multi-geometry experiments (tested)
• Speed improvement for detector initialization
• better isotropy in peak picking (add penalization term)
• enhanced documentation on http://pyfai.readthedocs.org
10.4. 0.11.0: 07/2015 269
![Page 274: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/274.jpg)
pyFAI Documentation, Release 0.15.0a0
0.10.3: 03/2015
• Image segmentation based on inverse watershed (only for recalib, not for calib)
• Python3 compatibility
• include testimages into distribution
0.10.2: 11/2014
• Update documentation
• Packaging for debian 8
0.10.1: 10/2014
• Fix issue in peak-picking
• Improve doc & manpages
• Compatibility with PyMca5
0.10.0: 10/2014
• Correct Caglioti’s formula
• Update tests and OpenCL -> works with Beignet and pocl open source drivers
• Compatibility with MacOSX and windows
0.9.4: 06/2014
• include spec of Maxwell GPU
• fix issues with intel OpenCL icd v4.4
• introduce shape & max_shape in detectors
• work on marchingsquares/sorted controurplot for calibration
• Enforce the use the Qt4Agg for Matplotlib and other GUI stuff.
• Update shape of detector in case of binning
• unified distortion class: merge OpenCL & OpenMP implementation #108
• Benchmarks for distortion
• Raise the level to warning when inverting the mask
• set of new ImXpad detectors Related issue #111
• Fix issue with recalib within MX-calibrate
• saving detector description in Nexus files issue #110
• Update some calibrants: gold
• about to make peak-picking more user-friendly
• test for bragg separation
270 Chapter 10. ChangeLog of Versions
![Page 275: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/275.jpg)
pyFAI Documentation, Release 0.15.0a0
• work on PEP8 compliance
• Do not re-cythonize: makes debian package generation able to benefit from ccache
• conversion to SPD (rotation is missing)
• pixelwise worker
• correct both LUT & OCL for memory error
• replace os.linsep with “n” when file file opened in text mode (not binary)
• rework the Extension part to be explicit instead of “black magic” :)
• implement Kahan summation in Cython (default still use Doubles: faster)
• Preprocessing kernel containing all cast to float kernels #120
• update setup for no-openmp option related to issue #127
• Add read-out mode for mar345 as “guess_binning” method for detector. Also for MAR and Rayonix #125
• tool to benchmark HDF5 writing
• try to be compatible with both PySide and PyQt4 ... the uic stuff is untested and probably buggy #130
• Deactivate the automatic saturation correction by default. now it is opt-in #131
0.9.3: 02/2014
• Better control for peak-picking (Contribution from Gero Flucke, Desy)
• Precise Rayonix detectors description thanks to Michael Blum
• Start integrating blob-detection algorithm for peak-picking: #70
• Switch fron OptParse to ArgPrse: #83
• Provide some calibrant by default: #91
• Description of Mar345 detector + mask#92
• Auto-registration of detectors: #97
• Recalib and check-calib can be called from calib: #99
• Fake diffraction image from calibrant: #101
• Implementation of the CSR matrix representation to replace LUT
• Tight pixel splitting: #43
• Update documentation
0.9.2: (01/2014)
• Fix memory leak in Cython part of the look-up table generation
• Benchmarks with memory profiling
0.9: 10/2013
• Add detector S140 from ImXpad, Titan from Agilent, Rayonix
• Fix issues: 61, 62, 68, 76, 81, 82, 85, 86, 87
• Enhancement in LImA plugins (better structure)
10.10. 0.9.3: 02/2014 271
![Page 276: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/276.jpg)
pyFAI Documentation, Release 0.15.0a0
• IO module with Ascii/EDF/HDF5 writers
• Switch some GUI to pyQtGraph in addition to Qt
• Correction for solid-angle formula
0.8: 10/2012
• Detector object is member of the geometry
• Binning of the detector, propagation to the spline if needed
• Detector object know about their masks.
• Automatic mask for some detectors like Pilatus or XPad
• Implementation of sub-pixel position correction for Pilatus detectors
• LUT implementation in 1D & 2D (fully tested) both with OpenMP and with OpenCL
• Switch from C++/Cython OpenCL framework to PyOpenCL
• Port opencl code to both Windows 32/64 bits and MacOSX
• Add polarization corrections
• Use fast-CRC checksum on x86 using SSE4 (when available) to track array change on GPU buffers
• Support for flat 7*8 modules Xpad detectors.
• Benchmark with live graphics (still a memory issue with python2.6)
• Fat source distribution (python setup.py sdist –with-test-images) for debian
• Enhanced tests, especially for Saxs and OpenCL
• Recalibration tool for refining automatically parameters
• Enhancement of peak picking (much faster, recoded in pure Cython)
• Easy calibration for pixel detector (reconstruction of inter-module space)
• Error-bar generation using Poisson law
• Unified programming interface for all integration methods in 2theta, q or radius unit
• Graphical interface for azimuthal integration (pyFAI-integrate)
• Lots of test to prevent non regression
• Tool for merging images using various method (mean, median) and with outlayer rejection
• LImA plugin which can perform azimuthal integration live during the acquisition
• Distortion correction is available alone and as LImA plugin
• Recalibration can refine the wavelength in addition to 6 other parameters
• Calibration always done vs calibrant’s ring number, lots of new calibrant are available
• Selection by hand of single peaks for calibration
• New detectors: Dexela and Perkin-Elmer flat panel
• Automatic refinement of multiple images at various geometries (for MX)
• Many improvements requested by ID11 and ID13
272 Chapter 10. ChangeLog of Versions
![Page 277: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/277.jpg)
pyFAI Documentation, Release 0.15.0a0
0.7.2: 08/2012
• Add diff_tomo script
• Geometry calculation optimized in (parallel) cython
0.7: 07/2012
Implementation of look-up table based integration and OpenCL version of it
0.6: 07/2012
• OpenCL flavor works well on GPU in double precision with device selection
0.5: 06/2012
• Include OpenCL version of azimuthal integration (based on histograms)
0.4: 06/2012
• Global clean up of the code regarding options from command line and better design
• Correct the orientation of the azimuthal angle chi
• Rename scripts in pyFAI-calib, pyFAI-saxs and pyFAI-waxs
0.3: 11/2011
• Azimuthal integration splits pixels like fit2d
0.2: 07/2011
• Azimuthal integration using cython histogramming is working
0.1: 05/2011
• Geometry is OK
10.14. 0.7.2: 08/2012 273
![Page 278: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/278.jpg)
pyFAI Documentation, Release 0.15.0a0
274 Chapter 10. ChangeLog of Versions
![Page 279: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/279.jpg)
CHAPTER 11
List of publication about pyFAI
• PyFAI, a versatile library for azimuthal regrouping, J Kieffer & D Karkoulis; Journal of Physics: Confer-ence Series (2013) 425 (20), pp202012
• PyFAI: a Python library for high performance azimuthal integration on GPU J Kieffer & J.P. Wright;Powder Diffraction (2013) 28 (S2), pp339-350
• PyFAI: a Python library for high performance azimuthal integration on GPU Jérôme Kieffer, GiannisAshiotis PROC. OF THE 7th EUR. CONF. ON PYTHON IN SCIENCE (EUROSCIPY 2014)
• The fast azimuthal integration Python library: pyFAI J. Kieffer, G. Ashiotis, A. Deschildre, Z. Nawaz, J. P.Wright, D. Karkoulis, F. E. Picca Journal of Applied Crystallography (2015) 48 (2), 510-519
The later publication provides a nice overview of the features introduced in version 0.11 and further developed inv0.12, v0.13 & v0.14 and should be the one cited in publications using pyFAI (or one of the graphical applicationon top of it). There are already 93 publication referring to pyFAI, some of them in the most prestigious scientificjournals (Nature, PNAS, ...).
275
![Page 280: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/280.jpg)
pyFAI Documentation, Release 0.15.0a0
276 Chapter 11. List of publication about pyFAI
![Page 281: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/281.jpg)
CHAPTER 12
Bibliography
277
![Page 282: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/282.jpg)
pyFAI Documentation, Release 0.15.0a0
278 Chapter 12. Bibliography
![Page 283: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/283.jpg)
CHAPTER 13
Glossary
You will find some explanation about technical terms often used in pyFAI and its documentation.
AzimuthalIntegrator
The azimuthal integrator (ai hereafter) is an object, in the sense of Object Oriented Programming which cantransform an image into a powder diffraction pattern using the integrate1d or integrate2d methods. It contains(inherits) a Geometry and caches the look-up table for optimized integration. Ai objects are usually obtained fromloading a PONI-file obtained after calibration. See AzimuthalIntegrator
Calibration
Action of determining the geometry of an experiment geometry using a reference sample. Calibration is performedusing the pyFAI-calib tool to generate the PONI-file., See its Calibration
Detector
Detectors are all area detectors in pyFAI, which mean pixels are indexed by 2 indices often references as (slow,fast) or (row, column) or simply (1, 2). Indices are using the C-convention. The detector object is responsiblefor calculating the pixel position in space (so in 3D). and assumes each pixel is defined by 4-corners. Detectorscan be defined by many ways: from a shape and a pixel size, from a tabulated detector (there are over 60 detectordefined) or from a NeXus file. See Simple detector
Distortion
Distortion correction is the action of correcting the spatial distortion from an image due to a detector. The objectis defined from detector and the target is an image with a regular grid and a given pixel size and shape.
279
![Page 284: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/284.jpg)
pyFAI Documentation, Release 0.15.0a0
Geometry
The geometry object is in charge of calculating all kind of coordinates (cartesian, polar, ...) for any point in theimage, a step both needed for integration and calibration. The geometry object composes (contains) a detectorand contains the 3 translations (dist, poni1 and poni2) and 3 rotations (rot1, rot2, rot3) of the detector in space. Itknows in addition about the wavelength. The object is saved in a PONI-file, see Detector position
Image
see Image representation in Python
PONI
Acronym for Point Of Normal Incidence. It is the pixel coordinates of the orthogonal projection of the sampleposition on the detector (for plane detectors, or the plane z=0 for other). The PONI coincide with the beam centerin the case of orthogonal setup but most of the time differs.
PONI-File
Small text file generated from pyFAi-calib or when saving a geometry object which contains the detector descrip-tion, its position in space and the wavelength. Used to initialize AzimuthalIntegrator or Geometry objects.
Worker
A worker allow, once parameterized, to perform always the same processing on all images in a stack, for exampleazimuthal integration, distortion correction or simple pixel-wise operation.
280 Chapter 13. Glossary
![Page 285: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/285.jpg)
CHAPTER 14
Indices and tables
• genindex
• modindex
• search
281
![Page 286: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/286.jpg)
pyFAI Documentation, Release 0.15.0a0
282 Chapter 14. Indices and tables
![Page 287: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/287.jpg)
Bibliography
[SRI2012] PyFAI, a versatile library for azimuthal regrouping J. Kieffer & D. Karkoulis J. Phys.: Conf. Ser. 425202012 http://dx.doi.org/10.1088/1742-6596/425/20/202012
[EPDIC13] PyFAI: a Python library for high performance azimuthal integration on GPU J. Kieffer & J. P. Wright,Powder Diffraction / Volume 28 / Supplement S2 / September 2013, pp S339-S350 http://dx.doi.org/10.1017/S0885715613000924
[FIT2D] Hammersley A. P., Svensson S. O., Hanfland M., Fitch A. N. and Hausermann D. 1996 High Press. Res.vol14 p235–248
[SPD] Bösecke P. 2007 J. Appl. Cryst. vol40 s423–s427
[EDNA] Incardona M. F., Bourenkov G. P., Levik K., Pieritz R. A., Popov A. N. and Svensson O. 2009 J.Synchrotron Rad. vol16 p872–879
[PyMca] Solé V. A., Papillon E., Cotte M., Walter P. and Susini J. 2007 Spectrochim. Acta Part B vol vol62 p63– 68
[PyNX] Favre-Nicolin V., Coraux J., Richard M. I. and Renevier H. 2011 J. Appl. Cryst. vol44 p635–640
[IPython] Pérez F and Granger B E 2007 Comput. Sci. Eng. vol9 p21–29 URL http://ipython.org
[NumPy] Oliphant T E 2007 Comput. Sci. Eng. vol9 p10–20
[Cython] Behnel S, Bradshaw R, Citro C, Dalcin L, Seljebotn D and Smith K 2011 Comput. Sci. Eng. vol13 p31–39
[OpenCL] Khronos OpenCL Working Group 2010 The OpenCL Specification, version 1.1 URL http://www.khronos.org/registry/cl/specs/opencl-1.1.pdf
[FabIO] Sorensen H O, Knudsen E, Wright J, Kieffer J et al. 2007–2013 FabIO: I/O library for images producedby 2D X-ray detectors URL http://fable.sf.net/
[Matplotlib] Hunter J D 2007 Comput. Sci. Eng. vol9 p90–95 ISSN 1521-9615
[SciPy] Jones E, Oliphant T, Peterson P et al. 2001– SciPy: Open source scientific tools for Python URL http://www.scipy.org/
[FFTw] Frigo M and Johnson S G 2005 Proceedings of the IEEE 93 p 216–231
[LImA] The LIMA Project Update S. Petitdemange, L. Claustre, A. Homs, R. Homs Regojo, E. Papillon Pro-ceedings of ICALEPCS2013 http://accelconf.web.cern.ch/AccelConf/ICALEPCS2013/html/auth1084.htm
[PyOpenCL] PyCUDA and PyOpenCL: A scripting-based approach to GPU run-time code generation AndreasKlöckner, Nicolas Pinto, Yunsup Lee, Bryan Catanzaro, Paul Ivanov, Ahmed Fasih, Parallel Computing Vol38, 3, March 2012, Pages 157–174 http://dx.doi.org/10.1016/j.parco.2011.09.001
283
![Page 288: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/288.jpg)
pyFAI Documentation, Release 0.15.0a0
[AMD] The American Mineralogist Crystal Structure Database. Downs, R.T. and Hall-Wallace, M. (2003) Amer-ican Mineralogist 88, 247-250 http://rruff.geo.arizona.edu/AMS/amcsd.php
[COD] Crystallography Open Database: an open-access collection of crystal structures and platform for world-wide collaboration Saulius Grazulis et al. Nucl. Acids Res. (2012) 40 (D1): D420-D427. http://dx.doi.org/10.1093/nar/gkr900 http://www.crystallography.net/
[Dpdak] A customizable software for fast reduction and analysis of large X-ray scattering data sets: applica-tions of the new DPDAK package to small angle X-ray scattering and grazing-incidence small angle X-rayscattering, Benecke, G. et al., (2014) J. Appl. Cryst. 47, http://dx.doi.org/10.1107/S1600576714019773
284 Bibliography
![Page 289: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/289.jpg)
Python Module Index
ppyFAI.__init__, 137pyFAI.average, 137pyFAI.azimuthalIntegrator, 143pyFAI.blob_detection, 209pyFAI.calibrant, 211pyFAI.control_points, 203pyFAI.detectors, 177pyFAI.distortion, 214pyFAI.ext.__init__, 231pyFAI.ext._bispev, 233pyFAI.ext._blob, 233pyFAI.ext._convolution, 234pyFAI.ext._distortion, 234pyFAI.ext._geometry, 237pyFAI.ext._tree, 243pyFAI.ext.bilinear, 232pyFAI.ext.histogram, 240pyFAI.ext.marchingsquares, 240pyFAI.ext.morphology, 241pyFAI.ext.preproc, 242pyFAI.ext.reconstruct, 241pyFAI.ext.relabel, 242pyFAI.ext.watershed, 244pyFAI.geometry, 153pyFAI.geometryRefinement, 171pyFAI.goniometer, 173pyFAI.gui.__init__, 231pyFAI.io, 198pyFAI.massif, 208pyFAI.multi_geometry, 152pyFAI.opencl, 226pyFAI.opencl.common, 226pyFAI.opencl.preproc, 228pyFAI.opencl.processing, 227pyFAI.peak_picker, 205pyFAI.spline, 195pyFAI.units, 219pyFAI.utils.__init__, 220pyFAI.utils.bayes, 224pyFAI.utils.shell, 225pyFAI.utils.stringutil, 226pyFAI.worker, 216
285
![Page 290: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/290.jpg)
pyFAI Documentation, Release 0.15.0a0
286 Python Module Index
![Page 291: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/291.jpg)
Index
Symbols__init__ (pyFAI.ext._tree.TreeItem attribute), 243__init__() (pyFAI.average.Average method), 137__init__() (pyFAI.average.AverageDarkFilter method),
139__init__() (pyFAI.average.MultiFilesAverageWriter
method), 141__init__() (pyFAI.azimuthalIntegrator.AzimuthalIntegrator
method), 143__init__() (pyFAI.blob_detection.BlobDetection
method), 209__init__() (pyFAI.calibrant.Calibrant method), 211__init__() (pyFAI.calibrant.CalibrantFactory method),
212__init__() (pyFAI.calibrant.Cell method), 212__init__() (pyFAI.control_points.ControlPoints
method), 203__init__() (pyFAI.control_points.PointGroup method),
204__init__() (pyFAI.detectors.ADSC_Q210 method), 177__init__() (pyFAI.detectors.ADSC_Q270 method), 177__init__() (pyFAI.detectors.ADSC_Q315 method), 178__init__() (pyFAI.detectors.ADSC_Q4 method), 178__init__() (pyFAI.detectors.Aarhus method), 178__init__() (pyFAI.detectors.Apex2 method), 179__init__() (pyFAI.detectors.Basler method), 179__init__() (pyFAI.detectors.Detector method), 179__init__() (pyFAI.detectors.DetectorMeta method), 182__init__() (pyFAI.detectors.Dexela2923 method), 182__init__() (pyFAI.detectors.Eiger method), 183__init__() (pyFAI.detectors.FReLoN method), 184__init__() (pyFAI.detectors.Fairchild method), 184__init__() (pyFAI.detectors.HF_130K method), 184__init__() (pyFAI.detectors.HF_1M method), 184__init__() (pyFAI.detectors.HF_262k method), 185__init__() (pyFAI.detectors.HF_2M method), 185__init__() (pyFAI.detectors.HF_4M method), 185__init__() (pyFAI.detectors.HF_9M method), 185__init__() (pyFAI.detectors.ImXPadS10 method), 186__init__() (pyFAI.detectors.ImXPadS140 method), 186__init__() (pyFAI.detectors.ImXPadS70 method), 187__init__() (pyFAI.detectors.Mar345 method), 187__init__() (pyFAI.detectors.NexusDetector method),
187__init__() (pyFAI.detectors.Perkin method), 188__init__() (pyFAI.detectors.Pilatus method), 188__init__() (pyFAI.detectors.Pixium method), 190__init__() (pyFAI.detectors.RaspberryPi5M method),
190__init__() (pyFAI.detectors.RaspberryPi8M method),
191__init__() (pyFAI.detectors.Rayonix method), 191__init__() (pyFAI.detectors.Rayonix133 method), 191__init__() (pyFAI.detectors.RayonixLx170 method),
191__init__() (pyFAI.detectors.RayonixLx255 method),
192__init__() (pyFAI.detectors.RayonixMx170 method),
192__init__() (pyFAI.detectors.RayonixMx225 method),
192__init__() (pyFAI.detectors.RayonixMx225hs method),
192__init__() (pyFAI.detectors.RayonixMx300 method),
193__init__() (pyFAI.detectors.RayonixMx300hs method),
193__init__() (pyFAI.detectors.RayonixMx325 method),
193__init__() (pyFAI.detectors.RayonixMx340hs method),
193__init__() (pyFAI.detectors.RayonixMx425hs method),
193__init__() (pyFAI.detectors.RayonixSx165 method),
194__init__() (pyFAI.detectors.RayonixSx200 method),
194__init__() (pyFAI.detectors.RayonixSx30hs method),
194__init__() (pyFAI.detectors.RayonixSx85hs method),
194__init__() (pyFAI.detectors.Titan method), 194__init__() (pyFAI.detectors.Xpad_flat method), 195__init__() (pyFAI.distortion.Distortion method), 214__init__() (pyFAI.distortion.Quad method), 215__init__() (pyFAI.ext._distortion.Distortion method),
234
287
![Page 292: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/292.jpg)
pyFAI Documentation, Release 0.15.0a0
__init__() (pyFAI.ext.watershed.InverseWatershedmethod), 244
__init__() (pyFAI.geometry.Geometry method), 160__init__() (pyFAI.geometryRefinement.GeometryRefinement
method), 171__init__() (pyFAI.goniometer.GeometryTransformation
method), 173__init__() (pyFAI.goniometer.Goniometer method),
174__init__() (pyFAI.goniometer.GoniometerRefinement
method), 175__init__() (pyFAI.goniometer.SingleGeometry
method), 176__init__() (pyFAI.io.AsciiWriter method), 198__init__() (pyFAI.io.DefaultAiWriter method), 198__init__() (pyFAI.io.FabioWriter method), 200__init__() (pyFAI.io.HDF5Writer method), 200__init__() (pyFAI.io.Nexus method), 200__init__() (pyFAI.io.Writer method), 202__init__() (pyFAI.massif.Massif method), 208__init__() (pyFAI.multi_geometry.MultiGeometry
method), 152__init__() (pyFAI.opencl.preproc.OCL_Preproc
method), 229__init__() (pyFAI.opencl.processing.OpenclProcessing
method), 227__init__() (pyFAI.peak_picker.ControlPoints method),
205__init__() (pyFAI.peak_picker.PeakPicker method),
206__init__() (pyFAI.peak_picker.PointGroup method),
208__init__() (pyFAI.spline.Spline method), 196__init__() (pyFAI.units.Unit method), 219__init__() (pyFAI.utils.__init__.lazy_property
method), 223__init__() (pyFAI.utils.bayes.BayesianBackground
method), 224__init__() (pyFAI.utils.shell.ProgressBar method), 225__init__() (pyFAI.worker.DistortionWorker method),
217__init__() (pyFAI.worker.PixelwiseWorker method),
217__init__() (pyFAI.worker.Worker method), 218
AAarhus (class in pyFAI.detectors), 178add_algorithm() (pyFAI.average.Average method), 137add_child() (pyFAI.ext._tree.TreeItem method), 243add_image() (pyFAI.average.ImageAccumulatorFilter
method), 139add_image() (pyFAI.average.ImageReductionFilter
method), 140add_image() (pyFAI.average.ImageStackFilter
method), 140add_or_discard() (py-
FAI.utils.__init__.FixedParameters method),220
ADSC_Q210 (class in pyFAI.detectors), 177ADSC_Q270 (class in pyFAI.detectors), 177ADSC_Q315 (class in pyFAI.detectors), 177ADSC_Q4 (class in pyFAI.detectors), 178algorithm_finished() (pyFAI.average.AverageObserver
method), 139algorithm_started() (pyFAI.average.AverageObserver
method), 139AlgorithmCreationError, 137aliases (pyFAI.detectors.ADSC_Q210 attribute), 177aliases (pyFAI.detectors.ADSC_Q270 attribute), 177aliases (pyFAI.detectors.ADSC_Q315 attribute), 178aliases (pyFAI.detectors.ADSC_Q4 attribute), 178aliases (pyFAI.detectors.Apex2 attribute), 179aliases (pyFAI.detectors.Basler attribute), 179aliases (pyFAI.detectors.Detector attribute), 179aliases (pyFAI.detectors.Dexela2923 attribute), 182aliases (pyFAI.detectors.Eiger16M attribute), 183aliases (pyFAI.detectors.Eiger1M attribute), 183aliases (pyFAI.detectors.Eiger4M attribute), 183aliases (pyFAI.detectors.Eiger500k attribute), 183aliases (pyFAI.detectors.Eiger9M attribute), 184aliases (pyFAI.detectors.Fairchild attribute), 184aliases (pyFAI.detectors.HF_130K attribute), 184aliases (pyFAI.detectors.HF_1M attribute), 184aliases (pyFAI.detectors.HF_262k attribute), 185aliases (pyFAI.detectors.HF_2M attribute), 185aliases (pyFAI.detectors.HF_4M attribute), 185aliases (pyFAI.detectors.HF_9M attribute), 185aliases (pyFAI.detectors.ImXPadS10 attribute), 186aliases (pyFAI.detectors.ImXPadS140 attribute), 186aliases (pyFAI.detectors.ImXPadS70 attribute), 187aliases (pyFAI.detectors.Mar345 attribute), 187aliases (pyFAI.detectors.Perkin attribute), 188aliases (pyFAI.detectors.Pilatus100k attribute), 188aliases (pyFAI.detectors.Pilatus1M attribute), 188aliases (pyFAI.detectors.Pilatus200k attribute), 189aliases (pyFAI.detectors.Pilatus2M attribute), 189aliases (pyFAI.detectors.Pilatus300k attribute), 189aliases (pyFAI.detectors.Pilatus300kw attribute), 189aliases (pyFAI.detectors.Pilatus6M attribute), 189aliases (pyFAI.detectors.PilatusCdTe1M attribute), 190aliases (pyFAI.detectors.PilatusCdTe2M attribute), 190aliases (pyFAI.detectors.PilatusCdTe300k attribute),
190aliases (pyFAI.detectors.PilatusCdTe300kw attribute),
190aliases (pyFAI.detectors.Pixium attribute), 190aliases (pyFAI.detectors.RaspberryPi5M attribute), 190aliases (pyFAI.detectors.RaspberryPi8M attribute), 191aliases (pyFAI.detectors.Rayonix133 attribute), 191aliases (pyFAI.detectors.RayonixLx170 attribute), 191aliases (pyFAI.detectors.RayonixLx255 attribute), 192aliases (pyFAI.detectors.RayonixMx170 attribute), 192aliases (pyFAI.detectors.RayonixMx225 attribute), 192aliases (pyFAI.detectors.RayonixMx225hs attribute),
192aliases (pyFAI.detectors.RayonixMx300 attribute), 193
288 Index
![Page 293: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/293.jpg)
pyFAI Documentation, Release 0.15.0a0
aliases (pyFAI.detectors.RayonixMx300hs attribute),193
aliases (pyFAI.detectors.RayonixMx325 attribute), 193aliases (pyFAI.detectors.RayonixMx340hs attribute),
193aliases (pyFAI.detectors.RayonixMx425hs attribute),
193aliases (pyFAI.detectors.RayonixSx165 attribute), 194aliases (pyFAI.detectors.RayonixSx200 attribute), 194aliases (pyFAI.detectors.RayonixSx30hs attribute), 194aliases (pyFAI.detectors.RayonixSx85hs attribute), 194aliases (pyFAI.detectors.Titan attribute), 194aliases (pyFAI.detectors.Xpad_flat attribute), 195allocate_buffers() (py-
FAI.opencl.processing.OpenclProcessingmethod), 228
allocate_cl_buffers() (in module py-FAI.opencl.common), 226
anneal() (pyFAI.geometryRefinement.GeometryRefinementmethod), 171
Apex2 (class in pyFAI.detectors), 178API_VERSION (pyFAI.detectors.Detector attribute),
179append() (pyFAI.control_points.ControlPoints
method), 203append() (pyFAI.peak_picker.ControlPoints method),
205append_2th() (pyFAI.calibrant.Calibrant method), 211append_2theta_deg() (py-
FAI.control_points.ControlPoints method),203
append_2theta_deg() (py-FAI.peak_picker.ControlPoints method),205
append_dSpacing() (pyFAI.calibrant.Calibrantmethod), 211
array (pyFAI.geometry.PolarizationArray attribute),170
array2spline() (pyFAI.spline.Spline method), 196array_from_unit() (pyFAI.geometry.Geometry
method), 160AsciiWriter (class in pyFAI.io), 198Average (class in pyFAI.average), 137average_dark() (in module pyFAI.average), 141average_images() (in module pyFAI.average), 141AverageDarkFilter (class in pyFAI.average), 139AverageObserver (class in pyFAI.average), 139AverageWriter (class in pyFAI.average), 139axis_offset (pyFAI.geometry.PolarizationDescription
attribute), 170AzimuthalIntegrator (class in py-
FAI.azimuthalIntegrator), 143
Bbackground_image() (py-
FAI.utils.bayes.BayesianBackgroundmethod), 224
Basler (class in pyFAI.detectors), 179
bayes_llk() (pyFAI.utils.bayes.BayesianBackgroundclass method), 224
bayes_llk_large() (py-FAI.utils.bayes.BayesianBackground classmethod), 224
bayes_llk_negative() (py-FAI.utils.bayes.BayesianBackground classmethod), 224
bayes_llk_small() (py-FAI.utils.bayes.BayesianBackground classmethod), 224
BayesianBackground (class in pyFAI.utils.bayes), 224benchmarks() (in module pyFAI.__init__), 137Bilinear (class in pyFAI.ext.bilinear), 232Bilinear (class in pyFAI.ext.watershed), 244bin() (pyFAI.spline.Spline method), 196binary_dilation() (in module pyFAI.ext.morphology),
241binary_erosion() (in module pyFAI.ext.morphology),
241BINNED_PIXEL_SIZE (pyFAI.detectors.Rayonix at-
tribute), 191BINNED_PIXEL_SIZE (pyFAI.detectors.Rayonix133
attribute), 191BINNED_PIXEL_SIZE (py-
FAI.detectors.RayonixLx170 attribute),191
BINNED_PIXEL_SIZE (py-FAI.detectors.RayonixLx255 attribute),192
BINNED_PIXEL_SIZE (py-FAI.detectors.RayonixMx170 attribute),192
BINNED_PIXEL_SIZE (py-FAI.detectors.RayonixMx225 attribute),192
BINNED_PIXEL_SIZE (py-FAI.detectors.RayonixMx225hs attribute),192
BINNED_PIXEL_SIZE (py-FAI.detectors.RayonixMx300 attribute),192
BINNED_PIXEL_SIZE (py-FAI.detectors.RayonixMx300hs attribute),193
BINNED_PIXEL_SIZE (py-FAI.detectors.RayonixMx325 attribute),193
BINNED_PIXEL_SIZE (py-FAI.detectors.RayonixMx340hs attribute),193
BINNED_PIXEL_SIZE (py-FAI.detectors.RayonixMx425hs attribute),193
BINNED_PIXEL_SIZE (py-FAI.detectors.RayonixSx165 attribute),193
BINNED_PIXEL_SIZE (py-
Index 289
![Page 294: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/294.jpg)
pyFAI Documentation, Release 0.15.0a0
FAI.detectors.RayonixSx200 attribute),194
BINNED_PIXEL_SIZE (py-FAI.detectors.RayonixSx30hs attribute),194
BINNED_PIXEL_SIZE (py-FAI.detectors.RayonixSx85hs attribute),194
binning (pyFAI.detectors.Detector attribute), 179binning (pyFAI.detectors.Rayonix attribute), 191binning() (in module pyFAI.utils.__init__), 220bisplev() (in module pyFAI.ext._bispev), 233BlobDetection (class in pyFAI.blob_detection), 209border (pyFAI.ext.watershed.Region attribute), 245BORDER_PIXEL_SIZE_RELATIVE (py-
FAI.detectors.ImXPadS140 attribute),186
BORDER_PIXEL_SIZE_RELATIVE (py-FAI.detectors.Xpad_flat attribute), 195
BORDER_SIZE_RELATIVE (py-FAI.detectors.ImXPadS10 attribute), 185
BORDER_SIZE_RELATIVE (py-FAI.detectors.ImXPadS70 attribute), 186
bounding_box() (in module pyFAI.average), 142BufferDescription (class in pyFAI.opencl.processing),
227buffers (pyFAI.opencl.preproc.OCL_Preproc attribute),
229buffers (pyFAI.opencl.processing.OpenclProcessing at-
tribute), 228
Ccalc_2th() (pyFAI.geometryRefinement.GeometryRefinement
method), 171calc_area() (in module pyFAI.ext._distortion), 235calc_area() (pyFAI.distortion.Quad method), 215calc_area_AB() (pyFAI.distortion.Quad method), 215calc_area_BC() (pyFAI.distortion.Quad method), 215calc_area_CD() (pyFAI.distortion.Quad method), 215calc_area_DA() (pyFAI.distortion.Quad method), 215calc_area_old() (pyFAI.distortion.Quad method), 215calc_area_vectorial() (pyFAI.distortion.Quad method),
216calc_cartesian_positions (in module py-
FAI.ext.bilinear), 232calc_cartesian_positions() (pyFAI.detectors.Aarhus
method), 178calc_cartesian_positions() (pyFAI.detectors.Detector
method), 179calc_cartesian_positions() (pyFAI.detectors.Eiger
method), 183calc_cartesian_positions() (py-
FAI.detectors.ImXPadS10 method), 186calc_cartesian_positions() (pyFAI.detectors.Pilatus
method), 188calc_cartesian_positions() (pyFAI.detectors.Xpad_flat
method), 195calc_checksum() (in module pyFAI.utils.__init__), 221
calc_chi() (in module pyFAI.ext._geometry), 237calc_cosa() (in module pyFAI.ext._geometry), 237calc_CSR() (in module pyFAI.ext._distortion), 235calc_delta_chi (in module pyFAI.ext._geometry), 238calc_init() (pyFAI.distortion.Distortion method), 214calc_LUT() (in module pyFAI.ext._distortion), 235calc_LUT() (pyFAI.distortion.Distortion method), 214calc_LUT() (pyFAI.ext._distortion.Distortion method),
234calc_LUT_size() (pyFAI.ext._distortion.Distortion
method), 234calc_mask() (pyFAI.detectors.Detector method), 180calc_mask() (pyFAI.detectors.Eiger method), 183calc_mask() (pyFAI.detectors.FReLoN method), 184calc_mask() (pyFAI.detectors.ImXPadS10 method),
186calc_mask() (pyFAI.detectors.Mar345 method), 187calc_mask() (pyFAI.detectors.Pilatus method), 188calc_mask() (pyFAI.detectors.PilatusCdTe method),
189calc_mask() (pyFAI.detectors.Rayonix133 method),
191calc_mask() (pyFAI.detectors.RayonixSx165 method),
194calc_mask() (pyFAI.detectors.Xpad_flat method), 195calc_openmp() (in module pyFAI.ext._distortion), 235calc_pixels_edges() (pyFAI.detectors.ImXPadS10
method), 186calc_pixels_edges() (pyFAI.detectors.Xpad_flat
method), 195calc_pos (in module pyFAI.ext._distortion), 236calc_pos() (pyFAI.distortion.Distortion method), 214calc_pos() (pyFAI.ext._distortion.Distortion method),
235calc_pos_zyx() (in module pyFAI.ext._geometry), 238calc_pos_zyx() (pyFAI.geometry.Geometry method),
161calc_q() (in module pyFAI.ext._geometry), 238calc_r() (in module pyFAI.ext._geometry), 239calc_rad_azim() (in module pyFAI.ext._geometry), 239calc_size (in module pyFAI.ext._distortion), 236calc_size() (pyFAI.distortion.Distortion method), 215calc_transmission() (pyFAI.geometry.Geometry
method), 161calc_tth() (in module pyFAI.ext._geometry), 239calcfrom1d() (pyFAI.geometry.Geometry method), 161calculate_massif() (pyFAI.massif.Massif method), 208Calibrant (class in pyFAI.calibrant), 211CALIBRANT_FACTORY (in module py-
FAI.calibrant), 211CalibrantFactory (class in pyFAI.calibrant), 212Cell (class in pyFAI.calibrant), 212center_array() (pyFAI.geometry.Geometry method),
162center_of_mass() (in module pyFAI.utils.__init__), 221check() (pyFAI.control_points.ControlPoints method),
203check() (pyFAI.peak_picker.ControlPoints method),
290 Index
![Page 295: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/295.jpg)
pyFAI Documentation, Release 0.15.0a0
205checksum (pyFAI.geometry.PolarizationArray at-
tribute), 170chi() (pyFAI.geometry.Geometry method), 162chi2() (pyFAI.geometryRefinement.GeometryRefinement
method), 171chi2() (pyFAI.goniometer.GoniometerRefinement
method), 175chi2_wavelength() (py-
FAI.geometryRefinement.GeometryRefinementmethod), 171
chi_corner() (pyFAI.geometry.Geometry method), 162chia (pyFAI.geometry.Geometry attribute), 163chiArray() (pyFAI.geometry.Geometry method), 162children (pyFAI.ext._tree.TreeItem attribute), 243classinit() (pyFAI.utils.bayes.BayesianBackground
class method), 224clear() (pyFAI.utils.shell.ProgressBar method), 226clip() (in module pyFAI.ext._distortion), 236close() (pyFAI.average.AverageWriter method), 139close() (pyFAI.average.MultiFilesAverageWriter
method), 141close() (pyFAI.io.DefaultAiWriter method), 198close() (pyFAI.io.HDF5Writer method), 200close() (pyFAI.io.Nexus method), 201closeGUI() (pyFAI.peak_picker.PeakPicker method),
207code (pyFAI.control_points.PointGroup attribute), 204code (pyFAI.peak_picker.PointGroup attribute), 208common_prefix() (in module pyFAI.average), 142comparison() (pyFAI.spline.Spline method), 196compile_kernels() (py-
FAI.opencl.preproc.OCL_Preproc method),229
compile_kernels() (py-FAI.opencl.processing.OpenclProcessingmethod), 228
confidence() (pyFAI.geometryRefinement.GeometryRefinementmethod), 171
CONFIG (pyFAI.io.HDF5Writer attribute), 200CONFIG_ITEMS (pyFAI.io.Writer attribute), 202contour() (pyFAI.peak_picker.PeakPicker method), 207ControlPoints (class in pyFAI.control_points), 203ControlPoints (class in pyFAI.peak_picker), 205convert_CamelCase() (in module pyFAI.utils.__init__),
221convert_corner_2D_to_4D (in module py-
FAI.ext.bilinear), 232corner_array() (pyFAI.geometry.Geometry method),
163cornerArray() (pyFAI.geometry.Geometry method),
163cornerQArray() (pyFAI.geometry.Geometry method),
163cornerRArray() (pyFAI.geometry.Geometry method),
163cornerRd2Array() (pyFAI.geometry.Geometry
method), 163
correct() (pyFAI.distortion.Distortion method), 215correct() (pyFAI.ext._distortion.Distortion method),
235correct() (pyFAI.spline.Spline method), 196correct_CSR() (in module pyFAI.ext._distortion), 236correct_LUT() (in module pyFAI.ext._distortion), 236correct_SA_spline (pyFAI.geometry.Geometry at-
tribute), 163cosIncidance() (pyFAI.geometry.Geometry method),
163countThem() (in module pyFAI.ext.relabel), 242cp_local_maxi() (pyFAI.ext.bilinear.Bilinear method),
232cp_local_maxi() (pyFAI.ext.watershed.Bilinear
method), 244create_algorithm() (in module pyFAI.average), 142create_mask() (pyFAI.azimuthalIntegrator.AzimuthalIntegrator
method), 144cubic() (pyFAI.calibrant.Cell class method), 212curve_fit() (pyFAI.geometryRefinement.GeometryRefinement
method), 171
Dd() (pyFAI.calibrant.Cell method), 212d_spacing() (pyFAI.calibrant.Cell method), 212dark_correction() (py-
FAI.azimuthalIntegrator.AzimuthalIntegratormethod), 144
darkcurrent (pyFAI.azimuthalIntegrator.AzimuthalIntegratorattribute), 144
darkcurrent (pyFAI.detectors.Detector attribute), 180darkfiles (pyFAI.azimuthalIntegrator.AzimuthalIntegrator
attribute), 144data (pyFAI.ext.bilinear.Bilinear attribute), 232data (pyFAI.ext.watershed.Bilinear attribute), 244DATASET_NAME (pyFAI.io.HDF5Writer attribute),
200deep_copy() (pyFAI.io.Nexus method), 201DEFAULT_METHOD (py-
FAI.azimuthalIntegrator.AzimuthalIntegratorattribute), 143
DEFAULT_PIXEL1 (pyFAI.detectors.Apex2 attribute),179
DEFAULT_PIXEL1 (pyFAI.detectors.Perkin attribute),187
DEFAULT_PIXEL1 (pyFAI.detectors.Pixium at-tribute), 190
DEFAULT_PIXEL2 (pyFAI.detectors.Apex2 attribute),179
DEFAULT_PIXEL2 (pyFAI.detectors.Perkin attribute),188
DEFAULT_PIXEL2 (pyFAI.detectors.Pixium at-tribute), 190
DefaultAiWriter (class in pyFAI.io), 198deg2rad() (in module pyFAI.utils.__init__), 221del_chia() (pyFAI.geometry.Geometry method), 163del_dssa() (pyFAI.geometry.Geometry method), 163del_qa() (pyFAI.geometry.Geometry method), 163
Index 291
![Page 296: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/296.jpg)
pyFAI Documentation, Release 0.15.0a0
del_ra() (pyFAI.geometry.Geometry method), 163del_ttha() (pyFAI.geometry.Geometry method), 163delta2Theta() (pyFAI.geometry.Geometry method), 163delta_array() (pyFAI.geometry.Geometry method), 164delta_dummy (pyFAI.opencl.preproc.OCL_Preproc at-
tribute), 230deltaChi() (pyFAI.geometry.Geometry method), 163deltaQ() (pyFAI.geometry.Geometry method), 164deltaR() (pyFAI.geometry.Geometry method), 164deltaRd2() (pyFAI.geometry.Geometry method), 164delValleySize() (pyFAI.massif.Massif method), 208Detector (class in pyFAI.detectors), 179DetectorMeta (class in pyFAI.detectors), 182Dexela2923 (class in pyFAI.detectors), 182diamond() (pyFAI.calibrant.Cell class method), 213diffSolidAngle() (pyFAI.geometry.Geometry method),
164direction() (pyFAI.blob_detection.BlobDetection
method), 210display_points() (pyFAI.peak_picker.PeakPicker
method), 207dist (pyFAI.geometry.Geometry attribute), 164dist (pyFAI.goniometer.PoniParam attribute), 176dist_max (pyFAI.geometryRefinement.GeometryRefinement
attribute), 172dist_min (pyFAI.geometryRefinement.GeometryRefinement
attribute), 172Distortion (class in pyFAI.distortion), 214Distortion (class in pyFAI.ext._distortion), 234DistortionWorker (class in pyFAI.worker), 217do_2D() (pyFAI.worker.Worker method), 218dog() (in module pyFAI.utils.__init__), 221dog_filter() (in module pyFAI.utils.__init__), 221dSpacing (pyFAI.calibrant.Calibrant attribute), 211dSpacing (pyFAI.control_points.ControlPoints at-
tribute), 203dSpacing (pyFAI.peak_picker.ControlPoints attribute),
205dssa (pyFAI.geometry.Geometry attribute), 164dtype (pyFAI.opencl.processing.BufferDescription at-
tribute), 227dummy (pyFAI.opencl.preproc.OCL_Preproc at-
tribute), 230
EEiger (class in pyFAI.detectors), 182Eiger16M (class in pyFAI.detectors), 183Eiger1M (class in pyFAI.detectors), 183Eiger4M (class in pyFAI.detectors), 183Eiger500k (class in pyFAI.detectors), 183Eiger9M (class in pyFAI.detectors), 183empty (pyFAI.azimuthalIntegrator.AzimuthalIntegrator
attribute), 144empty (pyFAI.opencl.preproc.OCL_Preproc attribute),
230eq_2th() (in module pyFAI.units), 220eq_q() (in module pyFAI.units), 220eq_r() (in module pyFAI.units), 220
error_model (pyFAI.worker.Worker attribute), 218event (pyFAI.opencl.processing.EventDescription at-
tribute), 227EventDescription (class in pyFAI.opencl.processing),
227expand() (in module pyFAI.utils.__init__), 221expand2d() (in module pyFAI.utils.__init__), 221expand_args() (in module pyFAI.utils.__init__), 222extra (pyFAI.ext._tree.TreeItem attribute), 243extract_cp() (pyFAI.goniometer.SingleGeometry
method), 177
Ff (in module pyFAI.average), 142f_cy() (pyFAI.ext.bilinear.Bilinear method), 232f_cy() (pyFAI.ext.watershed.Bilinear method), 244FabioWriter (class in pyFAI.io), 200factory() (pyFAI.detectors.Detector class method), 180Fairchild (class in pyFAI.detectors), 184fake_calibration_image() (pyFAI.calibrant.Calibrant
method), 211file_version (pyFAI.goniometer.Goniometer attribute),
174find_detector() (pyFAI.io.Nexus method), 201find_peaks() (pyFAI.massif.Massif method), 208finish() (pyFAI.peak_picker.PeakPicker method), 207first() (pyFAI.ext._tree.TreeItem method), 243FixedParameters (class in pyFAI.utils.__init__), 220flags (pyFAI.opencl.processing.BufferDescription at-
tribute), 227flat_correction() (pyFAI.azimuthalIntegrator.AzimuthalIntegrator
method), 144flatfield (pyFAI.azimuthalIntegrator.AzimuthalIntegrator
attribute), 145flatfield (pyFAI.detectors.Detector attribute), 180flatfiles (pyFAI.azimuthalIntegrator.AzimuthalIntegrator
attribute), 145fliplr() (pyFAI.spline.Spline method), 196fliplrud() (pyFAI.spline.Spline method), 196flipud() (pyFAI.spline.Spline method), 196float_() (in module pyFAI.utils.__init__), 222flush() (pyFAI.io.DefaultAiWriter method), 198flush() (pyFAI.io.HDF5Writer method), 200flush() (pyFAI.io.Writer method), 202force_pixel (pyFAI.detectors.Aarhus attribute), 178force_pixel (pyFAI.detectors.ADSC_Q210 attribute),
177force_pixel (pyFAI.detectors.ADSC_Q270 attribute),
177force_pixel (pyFAI.detectors.ADSC_Q315 attribute),
178force_pixel (pyFAI.detectors.ADSC_Q4 attribute), 178force_pixel (pyFAI.detectors.Apex2 attribute), 179force_pixel (pyFAI.detectors.Basler attribute), 179force_pixel (pyFAI.detectors.Detector attribute), 180force_pixel (pyFAI.detectors.Dexela2923 attribute),
182force_pixel (pyFAI.detectors.Eiger attribute), 183
292 Index
![Page 297: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/297.jpg)
pyFAI Documentation, Release 0.15.0a0
force_pixel (pyFAI.detectors.Fairchild attribute), 184force_pixel (pyFAI.detectors.HF_130K attribute), 184force_pixel (pyFAI.detectors.HF_1M attribute), 184force_pixel (pyFAI.detectors.HF_262k attribute), 185force_pixel (pyFAI.detectors.HF_2M attribute), 185force_pixel (pyFAI.detectors.HF_4M attribute), 185force_pixel (pyFAI.detectors.HF_9M attribute), 185force_pixel (pyFAI.detectors.ImXPadS10 attribute),
186force_pixel (pyFAI.detectors.ImXPadS140 attribute),
186force_pixel (pyFAI.detectors.ImXPadS70 attribute),
187force_pixel (pyFAI.detectors.Mar345 attribute), 187force_pixel (pyFAI.detectors.Perkin attribute), 188force_pixel (pyFAI.detectors.Pilatus attribute), 188force_pixel (pyFAI.detectors.Pixium attribute), 190force_pixel (pyFAI.detectors.RaspberryPi5M attribute),
190force_pixel (pyFAI.detectors.RaspberryPi8M attribute),
191force_pixel (pyFAI.detectors.Rayonix attribute), 191force_pixel (pyFAI.detectors.Rayonix133 attribute),
191force_pixel (pyFAI.detectors.RayonixLx170 attribute),
192force_pixel (pyFAI.detectors.RayonixMx225 attribute),
192force_pixel (pyFAI.detectors.RayonixMx225hs at-
tribute), 192force_pixel (pyFAI.detectors.RayonixMx300 attribute),
193force_pixel (pyFAI.detectors.RayonixMx300hs at-
tribute), 193force_pixel (pyFAI.detectors.RayonixMx340hs at-
tribute), 193force_pixel (pyFAI.detectors.RayonixSx165 attribute),
194force_pixel (pyFAI.detectors.Titan attribute), 194force_pixel (pyFAI.detectors.Xpad_flat attribute), 195frame_processed() (pyFAI.average.AverageObserver
method), 139free_buffers() (pyFAI.opencl.processing.OpenclProcessing
method), 228free_kernels() (pyFAI.opencl.processing.OpenclProcessing
method), 228FReLoN (class in pyFAI.detectors), 184from_dict() (pyFAI.detectors.Detector class method),
180from_isotime() (in module pyFAI.io), 202fully_qualified_name() (in module py-
FAI.utils.__init__), 222func2d_min() (pyFAI.utils.bayes.BayesianBackground
class method), 224func_min() (pyFAI.utils.bayes.BayesianBackground
class method), 225
Ggaussian() (in module pyFAI.ext._convolution), 234gaussian() (in module pyFAI.utils.__init__), 222gaussian_filter() (in module pyFAI.ext._convolution),
234gaussian_filter() (in module pyFAI.utils.__init__), 222Geometry (class in pyFAI.geometry), 153GeometryRefinement (class in py-
FAI.geometryRefinement), 171GeometryTransformation (class in pyFAI.goniometer),
173GeometryTranslation (in module pyFAI.goniometer),
174get() (pyFAI.calibrant.CalibrantFactory method), 212get() (pyFAI.control_points.ControlPoints method),
203get() (pyFAI.ext._tree.TreeItem method), 243get() (pyFAI.peak_picker.ControlPoints method), 205get() (pyFAI.units.Unit method), 219get_2th() (pyFAI.calibrant.Calibrant method), 211get_2th_index() (pyFAI.calibrant.Calibrant method),
211get_ai() (pyFAI.goniometer.Goniometer method), 174get_ai() (pyFAI.goniometer.SingleGeometry method),
177get_attr() (pyFAI.io.Nexus class method), 201get_binning() (pyFAI.detectors.Detector method), 180get_binning() (pyFAI.detectors.Rayonix method), 191get_borders() (pyFAI.ext.watershed.Region method),
245get_box() (pyFAI.distortion.Quad method), 216get_box_size0() (pyFAI.distortion.Quad method), 216get_box_size1() (pyFAI.distortion.Quad method), 216get_calibrant() (in module pyFAI.calibrant), 214get_calibration_dir() (in module pyFAI.utils.__init__),
222get_chia() (pyFAI.geometry.Geometry method), 165get_cl_file() (in module pyFAI.utils.__init__), 222get_class() (pyFAI.io.Nexus method), 201get_config() (pyFAI.worker.Worker method), 218get_correct_solid_angle_for_spline() (py-
FAI.geometry.Geometry method), 165get_counter_frames() (pyFAI.average.Average
method), 138get_darkcurrent() (py-
FAI.azimuthalIntegrator.AzimuthalIntegratormethod), 145
get_darkcurrent() (pyFAI.detectors.Detector method),180
get_darkcurrent_crc() (pyFAI.detectors.Detectormethod), 180
get_data() (pyFAI.io.Nexus method), 201get_dist() (pyFAI.geometry.Geometry method), 165get_dist_max() (pyFAI.geometryRefinement.GeometryRefinement
method), 172get_dist_min() (pyFAI.geometryRefinement.GeometryRefinement
method), 172
Index 293
![Page 298: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/298.jpg)
pyFAI Documentation, Release 0.15.0a0
get_dSpacing() (pyFAI.calibrant.Calibrant method),211
get_dSpacing() (pyFAI.control_points.ControlPointsmethod), 204
get_dSpacing() (pyFAI.peak_picker.ControlPointsmethod), 206
get_dssa() (pyFAI.geometry.Geometry method), 165get_empty() (pyFAI.azimuthalIntegrator.AzimuthalIntegrator
method), 145get_entries() (pyFAI.io.Nexus method), 201get_entry() (pyFAI.io.Nexus method), 201get_error_model() (pyFAI.worker.Worker method), 218get_fabio_image() (py-
FAI.average.MultiFilesAverageWritermethod), 141
get_fabio_images() (pyFAI.average.Average method),138
get_field() (pyFAI.utils.stringutil.SafeFormattermethod), 226
get_flatfield() (pyFAI.azimuthalIntegrator.AzimuthalIntegratormethod), 145
get_flatfield() (pyFAI.detectors.Detector method), 180get_flatfield_crc() (pyFAI.detectors.Detector method),
180get_highest_pass() (pyFAI.ext.watershed.Region
method), 245get_idx() (pyFAI.distortion.Quad method), 216get_image_reduction() (pyFAI.average.Average
method), 138get_index() (pyFAI.ext.watershed.Region method), 245get_isotime() (in module pyFAI.io), 202get_json_config() (pyFAI.worker.Worker method), 218get_label() (pyFAI.control_points.PointGroup class
method), 204get_label() (pyFAI.peak_picker.PointGroup class
method), 208get_labels() (pyFAI.control_points.ControlPoints
method), 204get_labels() (pyFAI.peak_picker.ControlPoints
method), 206get_mask() (pyFAI.detectors.Detector method), 180get_mask() (pyFAI.geometry.Geometry method), 165get_mask_crc() (pyFAI.detectors.Detector method),
180get_maskfile() (pyFAI.detectors.Detector method), 180get_maskfile() (pyFAI.geometry.Geometry method),
165get_maxi() (pyFAI.ext.watershed.Region method), 245get_mg() (pyFAI.goniometer.Goniometer method), 174get_mini() (pyFAI.ext.watershed.Region method), 245get_monitor_value() (in module pyFAI.average), 142get_name() (pyFAI.detectors.Detector method), 181get_neighbors() (pyFAI.ext.watershed.Region method),
245get_normalization_factor() (pyFAI.worker.Worker
method), 218get_offset0() (pyFAI.distortion.Quad method), 216get_offset1() (pyFAI.distortion.Quad method), 216
get_parameters() (pyFAI.average.AverageDarkFiltermethod), 139
get_parameters() (py-FAI.average.ImageReductionFilter method),140
get_pass_to() (pyFAI.ext.watershed.Region method),245
get_pixel1() (pyFAI.detectors.Detector method), 181get_pixel1() (pyFAI.geometry.Geometry method), 165get_pixel2() (pyFAI.detectors.Detector method), 181get_pixel2() (pyFAI.geometry.Geometry method), 165get_pixel_corners() (pyFAI.detectors.Aarhus method),
178get_pixel_corners() (pyFAI.detectors.Detector
method), 181get_pixel_corners() (pyFAI.detectors.ImXPadS10
method), 186get_pixel_corners() (pyFAI.detectors.Xpad_flat
method), 195get_poni1() (pyFAI.geometry.Geometry method), 165get_poni1_max() (py-
FAI.geometryRefinement.GeometryRefinementmethod), 172
get_poni1_min() (py-FAI.geometryRefinement.GeometryRefinementmethod), 172
get_poni2() (pyFAI.geometry.Geometry method), 165get_poni2_max() (py-
FAI.geometryRefinement.GeometryRefinementmethod), 172
get_poni2_min() (py-FAI.geometryRefinement.GeometryRefinementmethod), 172
get_position() (pyFAI.goniometer.SingleGeometrymethod), 177
get_qa() (pyFAI.geometry.Geometry method), 165get_ra() (pyFAI.geometry.Geometry method), 165get_result() (pyFAI.average.ImageAccumulatorFilter
method), 140get_result() (pyFAI.average.ImageReductionFilter
method), 140get_result() (pyFAI.average.ImageStackFilter method),
140get_result() (pyFAI.average.MeanAveraging method),
140get_ring() (pyFAI.control_points.PointGroup method),
204get_ring() (pyFAI.peak_picker.PointGroup method),
208get_rot1() (pyFAI.geometry.Geometry method), 165get_rot1_max() (pyFAI.geometryRefinement.GeometryRefinement
method), 172get_rot1_min() (pyFAI.geometryRefinement.GeometryRefinement
method), 172get_rot2() (pyFAI.geometry.Geometry method), 165get_rot2_max() (pyFAI.geometryRefinement.GeometryRefinement
method), 172get_rot2_min() (pyFAI.geometryRefinement.GeometryRefinement
294 Index
![Page 299: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/299.jpg)
pyFAI Documentation, Release 0.15.0a0
method), 172get_rot3() (pyFAI.geometry.Geometry method), 165get_rot3_max() (pyFAI.geometryRefinement.GeometryRefinement
method), 172get_rot3_min() (pyFAI.geometryRefinement.GeometryRefinement
method), 172get_shape() (pyFAI.geometry.Geometry method), 165get_size() (pyFAI.ext.watershed.Region method), 245get_spline() (pyFAI.geometry.Geometry method), 165get_splineFile() (pyFAI.detectors.Detector method),
181get_splineFile() (pyFAI.detectors.Pilatus method), 188get_splineFile() (pyFAI.geometry.Geometry method),
165get_ttha() (pyFAI.geometry.Geometry method), 165get_type() (pyFAI.calibrant.Cell method), 213get_ui_file() (in module pyFAI.utils.__init__), 222get_unit() (pyFAI.worker.Worker method), 218get_wavelength() (pyFAI.calibrant.Calibrant method),
211get_wavelength() (pyFAI.control_points.ControlPoints
method), 204get_wavelength() (pyFAI.geometry.Geometry method),
165get_wavelength() (pyFAI.peak_picker.ControlPoints
method), 206get_wavelength_max() (py-
FAI.geometryRefinement.GeometryRefinementmethod), 172
get_wavelength_min() (py-FAI.geometryRefinement.GeometryRefinementmethod), 172
getBinnedData() (pyFAI.massif.Massif method), 209getBluredData() (pyFAI.massif.Massif method), 209getFit2D() (pyFAI.detectors.Detector method), 180getFit2D() (pyFAI.detectors.NexusDetector method),
187getFit2D() (pyFAI.geometry.Geometry method), 164getLabeledMassif() (pyFAI.massif.Massif method),
209getList() (pyFAI.control_points.ControlPoints method),
203getList() (pyFAI.peak_picker.ControlPoints method),
205getList2theta() (pyFAI.control_points.ControlPoints
method), 203getList2theta() (pyFAI.peak_picker.ControlPoints
method), 206getListRing() (pyFAI.control_points.ControlPoints
method), 203getListRing() (pyFAI.peak_picker.ControlPoints
method), 206getMedianData() (pyFAI.massif.Massif method), 209getPixelSize() (pyFAI.spline.Spline method), 196getPyFAI() (pyFAI.detectors.Detector method), 180getPyFAI() (pyFAI.detectors.NexusDetector method),
187getPyFAI() (pyFAI.geometry.Geometry method), 165
getSPD() (pyFAI.geometry.Geometry method), 165getValleySize() (pyFAI.massif.Massif method), 209getWeightedList() (pyFAI.control_points.ControlPoints
method), 203getWeightedList() (pyFAI.peak_picker.ControlPoints
method), 206Goniometer (class in pyFAI.goniometer), 174GoniometerRefinement (class in pyFAI.goniometer),
175guess_binning() (pyFAI.detectors.Detector method),
181guess_binning() (pyFAI.detectors.Mar345 method),
187guess_binning() (pyFAI.detectors.Rayonix method),
191guess_poni() (pyFAI.geometryRefinement.GeometryRefinement
method), 172gui() (pyFAI.peak_picker.PeakPicker method), 207
Hhas_child() (pyFAI.ext._tree.TreeItem method), 243has_key() (pyFAI.calibrant.CalibrantFactory method),
212HAVE_TAPER (pyFAI.detectors.Detector attribute),
179HAVE_TAPER (pyFAI.detectors.FReLoN attribute),
184HDF5Writer (class in pyFAI.io), 200height (pyFAI.ext.bilinear.Bilinear attribute), 232height (pyFAI.ext.watershed.Bilinear attribute), 244help (pyFAI.peak_picker.PeakPicker attribute), 207hexagonal() (pyFAI.calibrant.Cell class method), 213HF_130K (class in pyFAI.detectors), 184HF_1M (class in pyFAI.detectors), 184HF_262k (class in pyFAI.detectors), 184HF_2M (class in pyFAI.detectors), 185HF_4M (class in pyFAI.detectors), 185HF_9M (class in pyFAI.detectors), 185highest_pass (pyFAI.ext.watershed.Region attribute),
245histogram() (in module pyFAI.ext.histogram), 240histogram2d() (in module pyFAI.ext.histogram), 240horizontal_convolution() (in module py-
FAI.ext._convolution), 234
Iimage_loaded() (pyFAI.average.AverageObserver
method), 139image_test() (in module pyFAI.blob_detection), 211ImageAccumulatorFilter (class in pyFAI.average), 139ImageReductionFilter (class in pyFAI.average), 140ImageStackFilter (class in pyFAI.average), 140ImXPadS10 (class in pyFAI.detectors), 185ImXPadS140 (class in pyFAI.detectors), 186ImXPadS70 (class in pyFAI.detectors), 186index (pyFAI.ext.watershed.Region attribute), 245init() (pyFAI.average.ImageAccumulatorFilter
method), 140
Index 295
![Page 300: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/300.jpg)
pyFAI Documentation, Release 0.15.0a0
init() (pyFAI.average.ImageReductionFilter method),140
init() (pyFAI.average.ImageStackFilter method), 140init() (pyFAI.ext.watershed.InverseWatershed method),
244init() (pyFAI.io.AsciiWriter method), 198init() (pyFAI.io.FabioWriter method), 200init() (pyFAI.io.HDF5Writer method), 200init() (pyFAI.io.Writer method), 202init() (pyFAI.peak_picker.PeakPicker method), 207init_borders() (pyFAI.ext.watershed.InverseWatershed
method), 245init_labels() (pyFAI.ext.watershed.InverseWatershed
method), 245init_pass() (pyFAI.ext.watershed.InverseWatershed
method), 245init_regions() (pyFAI.ext.watershed.InverseWatershed
method), 245init_slope() (pyFAI.distortion.Quad method), 216init_values() (pyFAI.ext.watershed.Region method),
245initValleySize() (pyFAI.massif.Massif method), 209inpainting() (pyFAI.azimuthalIntegrator.AzimuthalIntegrator
method), 145int_() (in module pyFAI.utils.__init__), 222integrate1d() (pyFAI.azimuthalIntegrator.AzimuthalIntegrator
method), 145integrate1d() (pyFAI.multi_geometry.MultiGeometry
method), 152integrate2d() (pyFAI.azimuthalIntegrator.AzimuthalIntegrator
method), 146integrate2d() (pyFAI.multi_geometry.MultiGeometry
method), 152integrate_radial() (py-
FAI.azimuthalIntegrator.AzimuthalIntegratormethod), 147
integrateAB() (pyFAI.distortion.Quad method), 216InverseWatershed (class in pyFAI.ext.watershed), 244is_algorithm_name_exists() (in module py-
FAI.average), 142IS_CONTIGUOUS (pyFAI.detectors.Detector at-
tribute), 179IS_CONTIGUOUS (pyFAI.detectors.Xpad_flat at-
tribute), 195is_far_from_group() (in module pyFAI.utils.__init__),
222IS_FLAT (pyFAI.detectors.Aarhus attribute), 178IS_FLAT (pyFAI.detectors.Detector attribute), 179is_hdf5() (in module pyFAI.io), 202isocontour() (in module pyFAI.ext.marchingsquares),
240items() (pyFAI.calibrant.CalibrantFactory method), 212
Kkernel_files (pyFAI.opencl.preproc.OCL_Preproc at-
tribute), 230kernel_files (pyFAI.opencl.processing.OpenclProcessing
attribute), 228
kernel_workgroup_size() (in module py-FAI.opencl.common), 227
keys() (pyFAI.calibrant.CalibrantFactory method), 212
Llabel (pyFAI.control_points.PointGroup attribute), 205label (pyFAI.ext._tree.TreeItem attribute), 243label (pyFAI.peak_picker.PointGroup attribute), 208last() (pyFAI.ext._tree.TreeItem method), 243last_label (pyFAI.control_points.PointGroup attribute),
205last_label (pyFAI.peak_picker.PointGroup attribute),
208lattices (pyFAI.calibrant.Cell attribute), 213lazy_property (class in pyFAI.utils.__init__), 223load() (pyFAI.control_points.ControlPoints method),
204load() (pyFAI.detectors.NexusDetector method), 187load() (pyFAI.ext.watershed.InverseWatershed class
method), 245load() (pyFAI.geometry.Geometry method), 165load() (pyFAI.peak_picker.ControlPoints method), 206load() (pyFAI.peak_picker.PeakPicker method), 207load_file() (pyFAI.calibrant.Calibrant method), 211local_max() (in module pyFAI.blob_detection), 211local_max() (in module pyFAI.ext._blob), 233local_maxi() (pyFAI.ext.bilinear.Bilinear method), 232local_maxi() (pyFAI.ext.watershed.Bilinear method),
244log_profile() (pyFAI.opencl.processing.OpenclProcessing
method), 228
Mmain() (in module pyFAI.spline), 198make_ai() (in module pyFAI.worker), 219make_gaussian() (in module pyFAI.blob_detection),
211make_headers() (pyFAI.geometry.Geometry method),
166make_headers() (pyFAI.io.DefaultAiWriter method),
198mapping (pyFAI.opencl.preproc.OCL_Preproc at-
tribute), 230Mar345 (class in pyFAI.detectors), 187marching_squares() (in module py-
FAI.ext.marchingsquares), 241mask (pyFAI.detectors.Detector attribute), 181mask (pyFAI.geometry.Geometry attribute), 166maskfile (pyFAI.detectors.Detector attribute), 181maskfile (pyFAI.geometry.Geometry attribute), 166Massif (class in pyFAI.massif), 208massif_contour() (pyFAI.peak_picker.PeakPicker
method), 207MAX_SHAPE (pyFAI.detectors.Aarhus attribute), 178MAX_SHAPE (pyFAI.detectors.ADSC_Q210 at-
tribute), 177MAX_SHAPE (pyFAI.detectors.ADSC_Q270 at-
tribute), 177
296 Index
![Page 301: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/301.jpg)
pyFAI Documentation, Release 0.15.0a0
MAX_SHAPE (pyFAI.detectors.ADSC_Q315 at-tribute), 177
MAX_SHAPE (pyFAI.detectors.ADSC_Q4 attribute),178
MAX_SHAPE (pyFAI.detectors.Apex2 attribute), 179MAX_SHAPE (pyFAI.detectors.Basler attribute), 179MAX_SHAPE (pyFAI.detectors.Dexela2923 attribute),
182MAX_SHAPE (pyFAI.detectors.Eiger16M attribute),
183MAX_SHAPE (pyFAI.detectors.Eiger1M attribute),
183MAX_SHAPE (pyFAI.detectors.Eiger4M attribute),
183MAX_SHAPE (pyFAI.detectors.Eiger500k attribute),
183MAX_SHAPE (pyFAI.detectors.Eiger9M attribute),
184MAX_SHAPE (pyFAI.detectors.Fairchild attribute),
184MAX_SHAPE (pyFAI.detectors.FReLoN attribute),
184MAX_SHAPE (pyFAI.detectors.HF_130K attribute),
184MAX_SHAPE (pyFAI.detectors.HF_1M attribute), 184MAX_SHAPE (pyFAI.detectors.HF_262k attribute),
185MAX_SHAPE (pyFAI.detectors.HF_2M attribute), 185MAX_SHAPE (pyFAI.detectors.HF_4M attribute), 185MAX_SHAPE (pyFAI.detectors.HF_9M attribute), 185MAX_SHAPE (pyFAI.detectors.ImXPadS10 attribute),
185MAX_SHAPE (pyFAI.detectors.ImXPadS140 at-
tribute), 186MAX_SHAPE (pyFAI.detectors.ImXPadS70 attribute),
186MAX_SHAPE (pyFAI.detectors.Mar345 attribute), 187MAX_SHAPE (pyFAI.detectors.Perkin attribute), 188MAX_SHAPE (pyFAI.detectors.Pilatus100k attribute),
188MAX_SHAPE (pyFAI.detectors.Pilatus1M attribute),
188MAX_SHAPE (pyFAI.detectors.Pilatus200k attribute),
189MAX_SHAPE (pyFAI.detectors.Pilatus2M attribute),
189MAX_SHAPE (pyFAI.detectors.Pilatus300k attribute),
189MAX_SHAPE (pyFAI.detectors.Pilatus300kw at-
tribute), 189MAX_SHAPE (pyFAI.detectors.Pilatus6M attribute),
189MAX_SHAPE (pyFAI.detectors.PilatusCdTe1M
attribute), 189MAX_SHAPE (pyFAI.detectors.PilatusCdTe2M
attribute), 190MAX_SHAPE (pyFAI.detectors.PilatusCdTe300k at-
tribute), 190
MAX_SHAPE (pyFAI.detectors.PilatusCdTe300kw at-tribute), 190
MAX_SHAPE (pyFAI.detectors.Pixium attribute), 190MAX_SHAPE (pyFAI.detectors.RaspberryPi5M at-
tribute), 190MAX_SHAPE (pyFAI.detectors.RaspberryPi8M at-
tribute), 191MAX_SHAPE (pyFAI.detectors.Rayonix attribute),
191MAX_SHAPE (pyFAI.detectors.Rayonix133 attribute),
191MAX_SHAPE (pyFAI.detectors.RayonixLx170 at-
tribute), 191MAX_SHAPE (pyFAI.detectors.RayonixLx255 at-
tribute), 192MAX_SHAPE (pyFAI.detectors.RayonixMx170
attribute), 192MAX_SHAPE (pyFAI.detectors.RayonixMx225
attribute), 192MAX_SHAPE (pyFAI.detectors.RayonixMx225hs at-
tribute), 192MAX_SHAPE (pyFAI.detectors.RayonixMx300
attribute), 192MAX_SHAPE (pyFAI.detectors.RayonixMx300hs at-
tribute), 193MAX_SHAPE (pyFAI.detectors.RayonixMx325
attribute), 193MAX_SHAPE (pyFAI.detectors.RayonixMx340hs at-
tribute), 193MAX_SHAPE (pyFAI.detectors.RayonixMx425hs at-
tribute), 193MAX_SHAPE (pyFAI.detectors.RayonixSx165 at-
tribute), 194MAX_SHAPE (pyFAI.detectors.RayonixSx200 at-
tribute), 194MAX_SHAPE (pyFAI.detectors.RayonixSx30hs at-
tribute), 194MAX_SHAPE (pyFAI.detectors.RayonixSx85hs at-
tribute), 194MAX_SHAPE (pyFAI.detectors.Titan attribute), 194MAX_SHAPE (pyFAI.detectors.Xpad_flat attribute),
195MaxAveraging (class in pyFAI.average), 140maxi (pyFAI.ext.bilinear.Bilinear attribute), 232maxi (pyFAI.ext.watershed.Bilinear attribute), 244maxi (pyFAI.ext.watershed.Region attribute), 245maximum_position() (in module pyFAI.utils.__init__),
223MeanAveraging (class in pyFAI.average), 140measure_offset() (in module pyFAI.utils.__init__), 223measure_workgroup_size() (in module py-
FAI.opencl.common), 227medfilt1d() (pyFAI.azimuthalIntegrator.AzimuthalIntegrator
method), 148merge() (pyFAI.ext.watershed.Region method), 245merge_intense() (pyFAI.ext.watershed.InverseWatershed
method), 245merge_singleton() (py-
Index 297
![Page 302: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/302.jpg)
pyFAI Documentation, Release 0.15.0a0
FAI.ext.watershed.InverseWatershedmethod), 245
merge_twins() (pyFAI.ext.watershed.InverseWatershedmethod), 245
mf (class in pyFAI.opencl.common), 226MinAveraging (class in pyFAI.average), 140mini (pyFAI.ext.bilinear.Bilinear attribute), 232mini (pyFAI.ext.watershed.Bilinear attribute), 244mini (pyFAI.ext.watershed.Region attribute), 245MODULE_GAP (pyFAI.detectors.Eiger attribute), 183MODULE_GAP (pyFAI.detectors.Pilatus attribute),
188MODULE_GAP (pyFAI.detectors.Xpad_flat attribute),
195MODULE_SIZE (pyFAI.detectors.Eiger attribute), 183MODULE_SIZE (pyFAI.detectors.ImXPadS10 at-
tribute), 185MODULE_SIZE (pyFAI.detectors.ImXPadS140
attribute), 186MODULE_SIZE (pyFAI.detectors.ImXPadS70 at-
tribute), 186MODULE_SIZE (pyFAI.detectors.Pilatus attribute),
188MODULE_SIZE (pyFAI.detectors.Xpad_flat attribute),
195MonitorNotFound, 140monoclinic() (pyFAI.calibrant.Cell class method), 213MultiFilesAverageWriter (class in pyFAI.average), 141MultiGeometry (class in pyFAI.multi_geometry), 152
Nname (pyFAI.average.AverageDarkFilter attribute), 139name (pyFAI.average.MaxAveraging attribute), 140name (pyFAI.average.MeanAveraging attribute), 140name (pyFAI.average.MinAveraging attribute), 140name (pyFAI.average.SumAveraging attribute), 141name (pyFAI.detectors.Detector attribute), 181name (pyFAI.ext._tree.TreeItem attribute), 243NAME (pyFAI.ext.watershed.InverseWatershed at-
tribute), 244name (pyFAI.opencl.processing.BufferDescription at-
tribute), 227name (pyFAI.opencl.processing.EventDescription at-
tribute), 227names() (in module pyFAI.calibrant), 214nearest_peak() (pyFAI.blob_detection.BlobDetection
method), 210nearest_peak() (pyFAI.massif.Massif method), 209neighbors (pyFAI.ext.watershed.Region attribute), 246new_class() (pyFAI.io.Nexus method), 201new_detector() (pyFAI.io.Nexus method), 202new_entry() (pyFAI.io.Nexus method), 202new_geometry() (py-
FAI.goniometer.GoniometerRefinementmethod), 175
new_instrument() (pyFAI.io.Nexus method), 202next() (pyFAI.ext._tree.TreeItem method), 243Nexus (class in pyFAI.io), 200
NexusDetector (class in pyFAI.detectors), 187normalization_factor (pyFAI.worker.Worker attribute),
218
OOCL_Preproc (class in pyFAI.opencl.preproc), 228on_minus_pts_clicked() (py-
FAI.peak_picker.PeakPicker method),207
on_option_clicked() (pyFAI.peak_picker.PeakPickermethod), 207
on_plus_pts_clicked() (pyFAI.peak_picker.PeakPickermethod), 207
on_refine_clicked() (pyFAI.peak_picker.PeakPickermethod), 207
onclick() (pyFAI.peak_picker.PeakPicker method), 207OpenclProcessing (class in pyFAI.opencl.processing),
227order (pyFAI.ext._tree.TreeItem attribute), 243orthorhombic() (pyFAI.calibrant.Cell class method),
213oversampleArray() (pyFAI.geometry.Geometry
method), 166
Pparent (pyFAI.ext._tree.TreeItem attribute), 243pass_to (pyFAI.ext.watershed.Region attribute), 246PeakPicker (class in pyFAI.peak_picker), 206peaks (pyFAI.ext.watershed.Region attribute), 246peaks_from_area() (py-
FAI.blob_detection.BlobDetection method),210
peaks_from_area() (py-FAI.ext.watershed.InverseWatershedmethod), 245
peaks_from_area() (pyFAI.massif.Massif method), 209peaks_from_area() (pyFAI.peak_picker.PeakPicker
method), 207Perkin (class in pyFAI.detectors), 187Pilatus (class in pyFAI.detectors), 188Pilatus100k (class in pyFAI.detectors), 188Pilatus1M (class in pyFAI.detectors), 188Pilatus200k (class in pyFAI.detectors), 189Pilatus2M (class in pyFAI.detectors), 189Pilatus300k (class in pyFAI.detectors), 189Pilatus300kw (class in pyFAI.detectors), 189Pilatus6M (class in pyFAI.detectors), 189PilatusCdTe (class in pyFAI.detectors), 189PilatusCdTe1M (class in pyFAI.detectors), 189PilatusCdTe2M (class in pyFAI.detectors), 190PilatusCdTe300k (class in pyFAI.detectors), 190PilatusCdTe300kw (class in pyFAI.detectors), 190pixel1 (pyFAI.detectors.Detector attribute), 181pixel1 (pyFAI.geometry.Geometry attribute), 166pixel2 (pyFAI.detectors.Detector attribute), 181pixel2 (pyFAI.geometry.Geometry attribute), 166PIXEL_EDGES (pyFAI.detectors.ImXPadS70 at-
tribute), 186
298 Index
![Page 303: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/303.jpg)
pyFAI Documentation, Release 0.15.0a0
PIXEL_SIZE (pyFAI.detectors.ImXPadS10 attribute),185
PIXEL_SIZE (pyFAI.detectors.ImXPadS140 attribute),186
PIXEL_SIZE (pyFAI.detectors.ImXPadS70 attribute),186
PIXEL_SIZE (pyFAI.detectors.Xpad_flat attribute),195
PixelwiseWorker (class in pyFAI.worker), 217Pixium (class in pyFAI.detectors), 190PointGroup (class in pyFAI.control_points), 204PointGroup (class in pyFAI.peak_picker), 208polarization() (pyFAI.geometry.Geometry method),
166polarization_factor (py-
FAI.geometry.PolarizationDescriptionattribute), 170
PolarizationArray (class in pyFAI.geometry), 170PolarizationDescription (class in pyFAI.geometry), 170poni1 (pyFAI.geometry.Geometry attribute), 166poni1 (pyFAI.goniometer.PoniParam attribute), 176poni1_max (pyFAI.geometryRefinement.GeometryRefinement
attribute), 172poni1_min (pyFAI.geometryRefinement.GeometryRefinement
attribute), 172poni2 (pyFAI.geometry.Geometry attribute), 166poni2 (pyFAI.goniometer.PoniParam attribute), 176poni2_max (pyFAI.geometryRefinement.GeometryRefinement
attribute), 172poni2_min (pyFAI.geometryRefinement.GeometryRefinement
attribute), 172PoniParam (class in pyFAI.goniometer), 176pop() (pyFAI.control_points.ControlPoints method),
204pop() (pyFAI.peak_picker.ControlPoints method), 206populate_box() (pyFAI.distortion.Quad method), 216position_array() (pyFAI.geometry.Geometry method),
166positionArray() (pyFAI.geometry.Geometry method),
166PREFACTOR (pyFAI.utils.bayes.BayesianBackground
attribute), 224preproc() (in module pyFAI.ext.preproc), 242preproc() (in module pyFAI.opencl.preproc), 230previous() (pyFAI.ext._tree.TreeItem method), 243process() (pyFAI.average.Average method), 138process() (pyFAI.blob_detection.BlobDetection
method), 210process() (pyFAI.opencl.preproc.OCL_Preproc
method), 230process() (pyFAI.worker.DistortionWorker method),
217process() (pyFAI.worker.PixelwiseWorker method),
218process() (pyFAI.worker.Worker method), 218process_finished() (pyFAI.average.AverageObserver
method), 139process_started() (pyFAI.average.AverageObserver
method), 139ProgressBar (class in pyFAI.utils.shell), 225pyFAI.__init__ (module), 137pyFAI.average (module), 137pyFAI.azimuthalIntegrator (module), 143pyFAI.blob_detection (module), 209pyFAI.calibrant (module), 211pyFAI.control_points (module), 203pyFAI.detectors (module), 177pyFAI.distortion (module), 214pyFAI.ext.__init__ (module), 231pyFAI.ext._bispev (module), 233pyFAI.ext._blob (module), 233pyFAI.ext._convolution (module), 234pyFAI.ext._distortion (module), 234pyFAI.ext._geometry (module), 237pyFAI.ext._tree (module), 243pyFAI.ext.bilinear (module), 232pyFAI.ext.histogram (module), 240pyFAI.ext.marchingsquares (module), 240pyFAI.ext.morphology (module), 241pyFAI.ext.preproc (module), 242pyFAI.ext.reconstruct (module), 241pyFAI.ext.relabel (module), 242pyFAI.ext.watershed (module), 244pyFAI.geometry (module), 153pyFAI.geometryRefinement (module), 171pyFAI.goniometer (module), 173pyFAI.gui.__init__ (module), 231pyFAI.io (module), 198pyFAI.massif (module), 208pyFAI.multi_geometry (module), 152pyFAI.opencl (module), 226pyFAI.opencl.common (module), 226pyFAI.opencl.preproc (module), 228pyFAI.opencl.processing (module), 227pyFAI.peak_picker (module), 205pyFAI.spline (module), 195pyFAI.units (module), 219pyFAI.utils.__init__ (module), 220pyFAI.utils.bayes (module), 224pyFAI.utils.shell (module), 225pyFAI.utils.stringutil (module), 226pyFAI.worker (module), 216
Qqa (pyFAI.geometry.Geometry attribute), 167qArray() (pyFAI.geometry.Geometry method), 167qCornerFunct() (pyFAI.geometry.Geometry method),
167qFunction() (pyFAI.geometry.Geometry method), 167Quad (class in pyFAI.distortion), 215
Rra (pyFAI.geometry.Geometry attribute), 167rArray() (pyFAI.geometry.Geometry method), 167RaspberryPi5M (class in pyFAI.detectors), 190RaspberryPi8M (class in pyFAI.detectors), 190
Index 299
![Page 304: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/304.jpg)
pyFAI Documentation, Release 0.15.0a0
Rayonix (class in pyFAI.detectors), 191Rayonix133 (class in pyFAI.detectors), 191RayonixLx170 (class in pyFAI.detectors), 191RayonixLx255 (class in pyFAI.detectors), 192RayonixMx170 (class in pyFAI.detectors), 192RayonixMx225 (class in pyFAI.detectors), 192RayonixMx225hs (class in pyFAI.detectors), 192RayonixMx300 (class in pyFAI.detectors), 192RayonixMx300hs (class in pyFAI.detectors), 193RayonixMx325 (class in pyFAI.detectors), 193RayonixMx340hs (class in pyFAI.detectors), 193RayonixMx425hs (class in pyFAI.detectors), 193RayonixSx165 (class in pyFAI.detectors), 193RayonixSx200 (class in pyFAI.detectors), 194RayonixSx30hs (class in pyFAI.detectors), 194RayonixSx85hs (class in pyFAI.detectors), 194rCornerFunct() (pyFAI.geometry.Geometry method),
167rd2Array() (pyFAI.geometry.Geometry method), 167read() (pyFAI.geometry.Geometry method), 167read() (pyFAI.spline.Spline method), 196READ_ONLY (pyFAI.opencl.common.mf attribute),
226READ_WRITE (pyFAI.opencl.common.mf attribute),
226readFloatFromKeyboard() (in module py-
FAI.utils.__init__), 223readRingNrFromKeyboard() (py-
FAI.control_points.ControlPoints method),204
readRingNrFromKeyboard() (py-FAI.peak_picker.ControlPoints method),206
reconfig() (pyFAI.worker.Worker method), 218reconstruct() (in module pyFAI.ext.reconstruct), 241refine1() (pyFAI.geometryRefinement.GeometryRefinement
method), 172refine2() (pyFAI.geometryRefinement.GeometryRefinement
method), 172refine2() (pyFAI.goniometer.GoniometerRefinement
method), 175refine2_wavelength() (py-
FAI.geometryRefinement.GeometryRefinementmethod), 172
refine_Hessian() (pyFAI.blob_detection.BlobDetectionmethod), 210
refine_Hessian_SG() (py-FAI.blob_detection.BlobDetection method),210
refinement() (pyFAI.blob_detection.BlobDetectionmethod), 210
Region (class in pyFAI.ext.watershed), 245register_radial_unit() (in module pyFAI.units), 220registry (pyFAI.detectors.Detector attribute), 181reinit() (pyFAI.distortion.Quad method), 216relabel() (in module pyFAI.utils.__init__), 223release_cl_buffers() (in module py-
FAI.opencl.common), 226
remove_grp() (pyFAI.peak_picker.PeakPicker method),208
remove_saturated_pixel() (in module pyFAI.average),143
reset() (pyFAI.azimuthalIntegrator.AzimuthalIntegratormethod), 148
reset() (pyFAI.control_points.ControlPoints method),204
reset() (pyFAI.distortion.Distortion method), 215reset() (pyFAI.geometry.Geometry method), 168reset() (pyFAI.peak_picker.ControlPoints method), 206reset() (pyFAI.peak_picker.PeakPicker method), 208reset() (pyFAI.worker.Worker method), 218reset_label() (pyFAI.control_points.PointGroup class
method), 205reset_label() (pyFAI.peak_picker.PointGroup class
method), 208reset_profile() (pyFAI.opencl.processing.OpenclProcessing
method), 228residu1() (pyFAI.geometryRefinement.GeometryRefinement
method), 172residu1_wavelength() (py-
FAI.geometryRefinement.GeometryRefinementmethod), 172
residu2() (pyFAI.geometryRefinement.GeometryRefinementmethod), 172
residu2() (pyFAI.goniometer.GoniometerRefinementmethod), 176
residu2_wavelength() (py-FAI.geometryRefinement.GeometryRefinementmethod), 172
residu2_wavelength_weighted() (py-FAI.geometryRefinement.GeometryRefinementmethod), 172
residu2_weighted() (py-FAI.geometryRefinement.GeometryRefinementmethod), 172
result_processing() (pyFAI.average.AverageObservermethod), 139
rFunction() (pyFAI.geometry.Geometry method), 167rhombohedral() (pyFAI.calibrant.Cell class method),
213ring (pyFAI.control_points.PointGroup attribute), 205ring (pyFAI.peak_picker.PointGroup attribute), 208roca() (pyFAI.geometryRefinement.GeometryRefinement
method), 172rot1 (pyFAI.geometry.Geometry attribute), 168rot1 (pyFAI.goniometer.PoniParam attribute), 176rot1_max (pyFAI.geometryRefinement.GeometryRefinement
attribute), 172rot1_min (pyFAI.geometryRefinement.GeometryRefinement
attribute), 172rot2 (pyFAI.geometry.Geometry attribute), 168rot2 (pyFAI.goniometer.PoniParam attribute), 176rot2_max (pyFAI.geometryRefinement.GeometryRefinement
attribute), 173rot2_min (pyFAI.geometryRefinement.GeometryRefinement
attribute), 173
300 Index
![Page 305: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/305.jpg)
pyFAI Documentation, Release 0.15.0a0
rot3 (pyFAI.geometry.Geometry attribute), 168rot3 (pyFAI.goniometer.PoniParam attribute), 176rot3_max (pyFAI.geometryRefinement.GeometryRefinement
attribute), 173rot3_min (pyFAI.geometryRefinement.GeometryRefinement
attribute), 173roundfft() (in module pyFAI.utils.__init__), 223
Ss1 (pyFAI.utils.bayes.BayesianBackground attribute),
225safe_format() (in module pyFAI.utils.stringutil), 226SafeFormatter (class in pyFAI.utils.stringutil), 226save() (pyFAI.calibrant.Cell method), 213save() (pyFAI.control_points.ControlPoints method),
204save() (pyFAI.detectors.Detector method), 181save() (pyFAI.ext.watershed.InverseWatershed
method), 245save() (pyFAI.geometry.Geometry method), 168save() (pyFAI.goniometer.Goniometer method), 174save() (pyFAI.peak_picker.ControlPoints method), 206save1D() (pyFAI.azimuthalIntegrator.AzimuthalIntegrator
method), 148save1D() (pyFAI.io.DefaultAiWriter method), 199save2D() (pyFAI.azimuthalIntegrator.AzimuthalIntegrator
method), 148save2D() (pyFAI.io.DefaultAiWriter method), 199save_config() (pyFAI.worker.Worker method), 218save_dSpacing() (pyFAI.calibrant.Calibrant method),
211saxs() (pyFAI.azimuthalIntegrator.AzimuthalIntegrator
method), 148selection_rules (pyFAI.calibrant.Cell attribute), 213send_buffer() (pyFAI.opencl.preproc.OCL_Preproc
method), 230separate() (pyFAI.azimuthalIntegrator.AzimuthalIntegrator
method), 148set_binning() (pyFAI.detectors.Detector method), 181set_binning() (pyFAI.detectors.Rayonix method), 191set_bounds() (pyFAI.goniometer.GoniometerRefinement
method), 176set_chia() (pyFAI.geometry.Geometry method), 169set_config() (pyFAI.detectors.Detector method), 181set_correct_flat_from_dark() (pyFAI.average.Average
method), 138set_correct_solid_angle_for_spline() (py-
FAI.geometry.Geometry method), 169set_dark() (pyFAI.average.Average method), 138set_darkcurrent() (py-
FAI.azimuthalIntegrator.AzimuthalIntegratormethod), 149
set_darkcurrent() (pyFAI.detectors.Detector method),182
set_darkfiles() (pyFAI.azimuthalIntegrator.AzimuthalIntegratormethod), 149
set_darkfiles() (pyFAI.detectors.Detector method), 182set_dist() (pyFAI.geometry.Geometry method), 169
set_dist_max() (pyFAI.geometryRefinement.GeometryRefinementmethod), 173
set_dist_min() (pyFAI.geometryRefinement.GeometryRefinementmethod), 173
set_dSpacing() (pyFAI.calibrant.Calibrant method),212
set_dSpacing() (pyFAI.control_points.ControlPointsmethod), 204
set_dSpacing() (pyFAI.peak_picker.ControlPointsmethod), 206
set_dssa() (pyFAI.geometry.Geometry method), 169set_dx() (pyFAI.detectors.Detector method), 182set_dy() (pyFAI.detectors.Detector method), 182set_empty() (pyFAI.azimuthalIntegrator.AzimuthalIntegrator
method), 149set_error_model() (pyFAI.worker.Worker method), 219set_filename() (pyFAI.io.DefaultAiWriter method), 199set_flat() (pyFAI.average.Average method), 138set_flatfield() (pyFAI.azimuthalIntegrator.AzimuthalIntegrator
method), 149set_flatfield() (pyFAI.detectors.Detector method), 182set_flatfiles() (pyFAI.azimuthalIntegrator.AzimuthalIntegrator
method), 149set_flatfiles() (pyFAI.detectors.Detector method), 182set_images() (pyFAI.average.Average method), 138set_kernel_arguments() (py-
FAI.opencl.preproc.OCL_Preproc method),230
set_label() (pyFAI.control_points.PointGroup classmethod), 205
set_label() (pyFAI.peak_picker.PointGroup classmethod), 208
set_mask() (pyFAI.detectors.Detector method), 182set_mask() (pyFAI.geometry.Geometry method), 169set_maskfile() (pyFAI.detectors.Detector method), 182set_maskfile() (pyFAI.geometry.Geometry method),
169set_monitor_name() (pyFAI.average.Average method),
138set_normalization_factor() (pyFAI.worker.Worker
method), 219set_observer() (pyFAI.average.Average method), 138set_param() (pyFAI.geometry.Geometry method), 169set_pixel1() (pyFAI.detectors.Detector method), 182set_pixel1() (pyFAI.geometry.Geometry method), 169set_pixel2() (pyFAI.detectors.Detector method), 182set_pixel2() (pyFAI.geometry.Geometry method), 169set_pixel_filter() (pyFAI.average.Average method), 138set_poni1() (pyFAI.geometry.Geometry method), 169set_poni1_max() (py-
FAI.geometryRefinement.GeometryRefinementmethod), 173
set_poni1_min() (py-FAI.geometryRefinement.GeometryRefinementmethod), 173
set_poni2() (pyFAI.geometry.Geometry method), 169set_poni2_max() (py-
FAI.geometryRefinement.GeometryRefinement
Index 301
![Page 306: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/306.jpg)
pyFAI Documentation, Release 0.15.0a0
method), 173set_poni2_min() (py-
FAI.geometryRefinement.GeometryRefinementmethod), 173
set_profiling() (pyFAI.opencl.processing.OpenclProcessingmethod), 228
set_qa() (pyFAI.geometry.Geometry method), 169set_ra() (pyFAI.geometry.Geometry method), 169set_ring() (pyFAI.control_points.PointGroup method),
205set_ring() (pyFAI.peak_picker.PointGroup method),
208set_rot1() (pyFAI.geometry.Geometry method), 169set_rot1_max() (pyFAI.geometryRefinement.GeometryRefinement
method), 173set_rot1_min() (pyFAI.geometryRefinement.GeometryRefinement
method), 173set_rot2() (pyFAI.geometry.Geometry method), 169set_rot2_max() (pyFAI.geometryRefinement.GeometryRefinement
method), 173set_rot2_min() (pyFAI.geometryRefinement.GeometryRefinement
method), 173set_rot3() (pyFAI.geometry.Geometry method), 169set_rot3_max() (pyFAI.geometryRefinement.GeometryRefinement
method), 173set_rot3_min() (pyFAI.geometryRefinement.GeometryRefinement
method), 173set_spline() (pyFAI.geometry.Geometry method), 169set_splineFile() (pyFAI.detectors.Detector method),
182set_splineFile() (pyFAI.detectors.Pilatus method), 188set_splineFile() (pyFAI.geometry.Geometry method),
169set_tolerance() (pyFAI.geometryRefinement.GeometryRefinement
method), 173set_ttha() (pyFAI.geometry.Geometry method), 169set_type() (pyFAI.calibrant.Cell method), 214set_unit() (pyFAI.worker.Worker method), 219set_wavelength() (pyFAI.calibrant.Calibrant method),
212set_wavelength() (pyFAI.control_points.ControlPoints
method), 204set_wavelength() (pyFAI.geometry.Geometry method),
169set_wavelength() (py-
FAI.multi_geometry.MultiGeometrymethod), 153
set_wavelength() (pyFAI.peak_picker.ControlPointsmethod), 206
set_wavelength_max() (py-FAI.geometryRefinement.GeometryRefinementmethod), 173
set_wavelength_min() (py-FAI.geometryRefinement.GeometryRefinementmethod), 173
set_writer() (pyFAI.average.Average method), 138setChiDiscAtPi() (pyFAI.geometry.Geometry method),
168
setChiDiscAtZero() (pyFAI.geometry.Geometrymethod), 168
setDarkcurrentFile() (pyFAI.worker.Worker method),219
setExtension() (pyFAI.worker.Worker method), 219setFit2D() (pyFAI.detectors.Detector method), 181setFit2D() (pyFAI.geometry.Geometry method), 168setFlatfieldFile() (pyFAI.worker.Worker method), 219setJsonConfig() (pyFAI.io.Writer method), 202setJsonConfig() (pyFAI.worker.Worker method), 219setOversampling() (pyFAI.geometry.Geometry
method), 168setPixelSize() (pyFAI.spline.Spline method), 196setPyFAI() (pyFAI.detectors.Detector method), 181setPyFAI() (pyFAI.geometry.Geometry method), 168setSPD() (pyFAI.geometry.Geometry method), 168setSubdir() (pyFAI.worker.Worker method), 219setup_CSR() (pyFAI.azimuthalIntegrator.AzimuthalIntegrator
method), 149setup_LUT() (pyFAI.azimuthalIntegrator.AzimuthalIntegrator
method), 150setValleySize() (pyFAI.massif.Massif method), 209setWavelength_change2th() (pyFAI.calibrant.Calibrant
method), 212setWavelength_change2th() (py-
FAI.control_points.ControlPoints method),204
setWavelength_change2th() (py-FAI.peak_picker.ControlPoints method),206
setWavelength_changeDs() (pyFAI.calibrant.Calibrantmethod), 212
setWavelength_changeDs() (py-FAI.control_points.ControlPoints method),204
setWavelength_changeDs() (py-FAI.peak_picker.ControlPoints method),206
shape_out (pyFAI.distortion.Distortion attribute), 215shift() (in module pyFAI.utils.__init__), 223shiftFFT() (in module pyFAI.utils.__init__), 223show_neighboor() (py-
FAI.blob_detection.BlobDetection method),211
show_stats() (pyFAI.blob_detection.BlobDetectionmethod), 211
sigma_clip() (pyFAI.azimuthalIntegrator.AzimuthalIntegratormethod), 150
simplex() (pyFAI.geometryRefinement.GeometryRefinementmethod), 173
SingleGeometry (class in pyFAI.goniometer), 176size (pyFAI.ext._tree.TreeItem attribute), 243size (pyFAI.ext.watershed.Region attribute), 246size (pyFAI.opencl.processing.BufferDescription at-
tribute), 227sload() (pyFAI.detectors.NexusDetector class method),
187sload() (pyFAI.geometry.Geometry class method), 169
302 Index
![Page 307: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/307.jpg)
pyFAI Documentation, Release 0.15.0a0
sload() (pyFAI.goniometer.Goniometer class method),175
solidAngleArray() (pyFAI.geometry.Geometrymethod), 169
sort() (pyFAI.ext._tree.TreeItem method), 243sort_edges() (in module pyFAI.ext.marchingsquares),
241Spline (class in pyFAI.spline), 195spline (pyFAI.geometry.Geometry attribute), 170spline (pyFAI.utils.bayes.BayesianBackground at-
tribute), 225spline2array() (pyFAI.spline.Spline method), 197splineFile (pyFAI.detectors.Detector attribute), 182splineFile (pyFAI.detectors.Pilatus attribute), 188splineFile (pyFAI.geometry.Geometry attribute), 170splineFuncX() (pyFAI.spline.Spline method), 197splineFuncY() (pyFAI.spline.Spline method), 197str_() (in module pyFAI.utils.__init__), 224SumAveraging (class in pyFAI.average), 141sync_init() (pyFAI.peak_picker.PeakPicker method),
208
TTARGET_SIZE (pyFAI.massif.Massif attribute), 208test() (in module pyFAI.distortion), 216test_bayes_llk() (pyFAI.utils.bayes.BayesianBackground
class method), 225tests() (in module pyFAI.__init__), 137tetragonal() (pyFAI.calibrant.Cell class method), 214tilt() (pyFAI.spline.Spline method), 197Titan (class in pyFAI.detectors), 194to_dict() (pyFAI.goniometer.GeometryTransformation
method), 174to_dict() (pyFAI.goniometer.Goniometer method), 175to_unit() (in module pyFAI.units), 220TreeItem (class in pyFAI.ext._tree), 243tresh (pyFAI.blob_detection.BlobDetection attribute),
211tth() (pyFAI.geometry.Geometry method), 170tth_corner() (pyFAI.geometry.Geometry method), 170ttha (pyFAI.geometry.Geometry attribute), 170twoThetaArray() (pyFAI.geometry.Geometry method),
170type (pyFAI.calibrant.Cell attribute), 214type (pyFAI.ext._tree.TreeItem attribute), 243types (pyFAI.calibrant.Cell attribute), 214
UunBinning() (in module pyFAI.utils.__init__), 224uncorrect() (pyFAI.distortion.Distortion method), 215uncorrect() (pyFAI.ext._distortion.Distortion method),
235uncorrect_CSR() (in module pyFAI.ext._distortion),
236uncorrect_LUT() (in module pyFAI.ext._distortion),
237uniform_pixel (pyFAI.detectors.Detector attribute), 182
uniform_pixel (pyFAI.detectors.Fairchild attribute),184
uniform_pixel (pyFAI.detectors.ImXPadS10 attribute),186
uniform_pixel (pyFAI.detectors.Titan attribute), 194uniform_pixel (pyFAI.detectors.Xpad_flat attribute),
195Unit (class in pyFAI.units), 219unit (pyFAI.worker.Worker attribute), 219update() (pyFAI.ext._tree.TreeItem method), 243update() (pyFAI.utils.shell.ProgressBar method), 226
VVALID_METHODS (pyFAI.peak_picker.PeakPicker
attribute), 206VALID_SIZE (pyFAI.detectors.Mar345 attribute), 187valley_size (pyFAI.massif.Massif attribute), 209values() (pyFAI.calibrant.CalibrantFactory method),
212VERSION (pyFAI.ext.watershed.InverseWatershed at-
tribute), 244vertical_convolution() (in module py-
FAI.ext._convolution), 234volume (pyFAI.calibrant.Cell attribute), 214
Wwarmup() (pyFAI.worker.Worker method), 219wavelength (pyFAI.calibrant.Calibrant attribute), 212wavelength (pyFAI.control_points.ControlPoints
attribute), 204wavelength (pyFAI.geometry.Geometry attribute), 170wavelength (pyFAI.peak_picker.ControlPoints at-
tribute), 206wavelength_max (py-
FAI.geometryRefinement.GeometryRefinementattribute), 173
wavelength_min (py-FAI.geometryRefinement.GeometryRefinementattribute), 173
width (pyFAI.ext.bilinear.Bilinear attribute), 232width (pyFAI.ext.watershed.Bilinear attribute), 244Worker (class in pyFAI.worker), 218write() (pyFAI.geometry.Geometry method), 170write() (pyFAI.goniometer.Goniometer method), 175write() (pyFAI.io.AsciiWriter method), 198write() (pyFAI.io.DefaultAiWriter method), 199write() (pyFAI.io.FabioWriter method), 200write() (pyFAI.io.HDF5Writer method), 200write() (pyFAI.io.Writer method), 202write() (pyFAI.spline.Spline method), 197write_header() (pyFAI.average.AverageWriter
method), 139write_header() (pyFAI.average.MultiFilesAverageWriter
method), 141WRITE_ONLY (pyFAI.opencl.common.mf attribute),
226write_reduction() (pyFAI.average.AverageWriter
method), 139
Index 303
![Page 308: pyFAI Documentation · 2019-04-02 · pyFAI Documentation, Release 0.15.0a0 PyFAI is a python libary for azimuthal integration of diffraction data acquired with 2D detectors, providing](https://reader035.vdocuments.us/reader035/viewer/2022081521/5ec99eae81fedd21814d8ac7/html5/thumbnails/308.jpg)
pyFAI Documentation, Release 0.15.0a0
write_reduction() (py-FAI.average.MultiFilesAverageWritermethod), 141
writeEDF() (pyFAI.spline.Spline method), 197Writer (class in pyFAI.io), 202
XXpad_flat (class in pyFAI.detectors), 194xrpd() (pyFAI.azimuthalIntegrator.AzimuthalIntegrator
method), 151xrpd2() (pyFAI.azimuthalIntegrator.AzimuthalIntegrator
method), 151xrpd2_histogram() (py-
FAI.azimuthalIntegrator.AzimuthalIntegratormethod), 151
xrpd2_numpy() (pyFAI.azimuthalIntegrator.AzimuthalIntegratormethod), 151
xrpd2_splitBBox() (py-FAI.azimuthalIntegrator.AzimuthalIntegratormethod), 151
xrpd2_splitPixel() (py-FAI.azimuthalIntegrator.AzimuthalIntegratormethod), 151
xrpd_CSR_OCL() (py-FAI.azimuthalIntegrator.AzimuthalIntegratormethod), 151
xrpd_cython() (pyFAI.azimuthalIntegrator.AzimuthalIntegratormethod), 151
xrpd_LUT() (pyFAI.azimuthalIntegrator.AzimuthalIntegratormethod), 151
xrpd_LUT_OCL() (py-FAI.azimuthalIntegrator.AzimuthalIntegratormethod), 151
xrpd_numpy() (pyFAI.azimuthalIntegrator.AzimuthalIntegratormethod), 151
xrpd_OpenCL() (pyFAI.azimuthalIntegrator.AzimuthalIntegratormethod), 151
xrpd_splitBBox() (py-FAI.azimuthalIntegrator.AzimuthalIntegratormethod), 151
xrpd_splitPixel() (py-FAI.azimuthalIntegrator.AzimuthalIntegratormethod), 151
Zzeros() (pyFAI.spline.Spline method), 198zeros_like() (pyFAI.spline.Spline method), 198
304 Index