Scripting 2D Powder Diffraction Data Reduction with DAWN and PyFAI
Introduction
PyFAI is a powerful library developed at the ESRF for reduction of 2D powder diffraction images. If you have DAWN and PyFAI installed on your computer it is possible to use the calibration metadata produced by DAWN with the integration routines in PYFAI.
Setting up the Python Interpreter
Assuming you already have a python interpreter and PyFAI already installed.
- In DAWN, go to Window/Preferences then PyDev/Interpreters/Python interpreters select new and locate your python interpreter (if you only have one and it is on the path the Auto-config methods should work).
- Go to the DAWN python perspective, and in the console view select Open Console, Pydev Console, Python Console, to start the interpreter.
Using PyFAI in DAWN [> 2.0 now use NX transform to hold orientation]
Assuming you have a NeXus file from DAWN containing the calibration metadata, the following lines of code can be used to construct a PyFAI azimuthal integrator object.
import pyFAI import scisoftpy as dnp import scisoftpy.io as dio ai = pyFAI.AzimuthalIntegrator() nexusFile = dio.load("/path/to/calibration/nexus/file.nxs") #Load geometry and energy into PyFAI px = nexusFile['/entry1/instrument/detector/detector_module/fast_pixel_direction'][...] bc = [nexusFile['/entry1/instrument/detector/beam_center_x'][...], nexusFile['/entry1/instrument/detector/beam_center_y'][...]] distance = nexusFile['/entry1/instrument/detector/distance'][...] wavelength = nexusFile['/entry1/calibration_sample/beam/incident_wavelength'][...] px = nexusFile['/entry1/instrument/detector/detector_module/fast_pixel_direction'][...] eub = nexusFile['/entry1/instrument/detector/transformations/euler_b'][...] euc = nexusFile['/entry1/instrument/detector/transformations/euler_c'][...] #set ai.setFit2D(distance, bc[0]/px, bc[1]/px, eub, euc, px*1000., px*1000.0, None) ai.set_wavelength(wavelength*10e-10); ai.set_wavelength(energy);
The azimuthal integrator object (ai) can then be used to integrate your powder images.
Using PyFAI in DAWN [< 2.0]
Assuming you have a NeXus file from DAWN containing the calibration metadata, the following lines of code can be used to construct a PyFAI azimuthal integrator object.
import pyFAI import scisoftpy as dnp import scisoftpy.io as dio ai = pyFAI.AzimuthalIntegrator() nexusFile = dio.load("/path/to/calibration/nexus/file.nxs") #Load geometry and energy into PyFAI bc = [nexusFile['/entry/instrument/detector/beam_center_x'][...], nexusFile['/entry/instrument/detector/beam_center_y'][...]] distance = nexusFile['/entry/instrument/detector/distance'][...] energy = nexusFile['/entry/calibration_sample/beam/incident_wavelength'][...][0] px = nexusFile['/entry/instrument/detector/x_pixel_size'][...]*1000 orien = nexusFile['/entry/instrument/detector/detector_orientation'][...].reshape((3,3)) #Transform yaw = math.degrees(-math.atan2(orien[2,0], orien[2,2])) roll = math.degrees(-math.atan2(orien[0,1], orien[1,1])) #set ai.setFit2D(distance, bc[0],bc[1], -yaw, roll, px, px, None) ai.set_wavelength(energy);
The azimuthal integrator object (ai) can then be used to integrate your powder images.