diffraction
Module¶
This module creates a namespace for X-Ray Diffraction
-
class
skbeam.diffraction.
BasicElement
(Z, *args, **kwargs)¶ Bases:
object
Object to return basic elemental information
- Parameters
- elementstr or int
Element symbol, name or atomic number (‘Zinc’, ‘Zn’ or 30)
Examples
>>> # Create an `Element` object >>> e = Element('Zn') # or e = Element(30) >>> # get the atomic mass >>> e.mass 65.37 >>> # get the density in grams / cm^3 >>> e.density 7.14
- Attributes
- Zint
Atomic number
- symstr
Element symbol (Fe, Cr, etc.)
- namestr
Full element name (Iron, Chromium, etc.
- atomic_radiusfloat
AtomicRadius[A]
- covalent_radiusfloat
CovalentRadius[A]
- massfloat
AtomicMass
- bpfloat
BoilingPoint[K]
- mpfloat
MeltingPoint[K]
- densityfloat
Density[g/ccm]
- atomic_volumefloat
AtomicVolume
- coherent_scattering_lengthfloat
CoherentScatteringLength[1E-12cm]
- incoherent_crosssectionfloat
IncoherentX-section[barn]
- absorptionfloat
Absorption@1.8A[barn]
- debye_tempfloat
DebyeTemperature[K]
- thermal_conductivityfloat
ThermalConductivity[W/cmK]
-
class
skbeam.diffraction.
Lorentzian2Model
(*args, **kwargs)¶ Bases:
lmfit.model.Model
Wrap the lorentzian2 function for fitting within lmfit framework 1-d lorentzian squared profile
- Parameters
- xarray
independent variable
- areafloat
area of lorentzian squared peak, If area is set as 1, the integral is unity.
- centerfloat
center position
- sigmafloat
standard deviation
-
skbeam.diffraction.
gaussian
(x, area, center, sigma)¶ 1 dimensional gaussian
- Parameters
- xarray
independent variable
- areafloat
Area of the normally distributed peak
- centerfloat
center position
- sigmafloat
standard deviation
-
skbeam.diffraction.
lorentzian
(x, area, center, sigma)¶ 1 dimensional lorentzian
- Parameters
- xarray
independent variable
- areafloat
area of lorentzian peak, If area is set as 1, the integral is unity.
- centerfloat
center position
- sigmafloat
standard deviation
-
skbeam.diffraction.
lorentzian2
(x, area, center, sigma)¶ 1-d lorentzian squared profile
- Parameters
- xarray
independent variable
- areafloat
area of lorentzian squared peak, If area is set as 1, the integral is unity.
- centerfloat
center position
- sigmafloat
standard deviation
-
skbeam.diffraction.
voigt
(x, area, center, sigma, gamma=None)¶ Convolution of gaussian and lorentzian curve.
see http://en.wikipedia.org/wiki/Voigt_profile
- Parameters
- xarray
independent variable
- areafloat
area of voigt peak
- centerfloat
center position
- sigmafloat
standard deviation
- gammafloat, optional
half width at half maximum of lorentzian. If optional, gamma gets set to sigma
-
skbeam.diffraction.
pvoigt
(x, area, center, sigma, fraction)¶ Linear combination of gaussian and lorentzian
- Parameters
- xarray
independent variable
- areafloat
area of pvoigt peak
- centerfloat
center position
- sigmafloat
standard deviation
- fractionfloat
weight for lorentzian peak in the linear combination, and (1-fraction) is the weight for gaussian peak.
-
skbeam.diffraction.
gaussian_tail
(x, area, center, sigma, gamma)¶ Use a gaussian tail function to simulate compton peak
- Parameters
- xarray
data in x coordinate
- areafloat
area of gauss tail function If area is set as 1, the integral is unity.
- centerfloat
center position
- sigmafloat
control peak width
- gammafloat
normalization factor
- Returns
- countsarray
gaussian tail peak
References
- 1
Rene Van Grieken, “Handbook of X-Ray Spectrometry, Second Edition, (Practical Spectroscopy)”, CRC Press, 2 edition, pp. 182, 2007.
-
skbeam.diffraction.
gausssian_step
(x, area, center, sigma, peak_e)¶ Gauss step function is an important component in modeling compton peak. Use scipy erfc function. Please note erfc = 1-erf.
- Parameters
- xarray
data in x coordinate
- areafloat
area of gauss step function
- centerfloat
center position
- sigmafloat
standard deviation
- peak_efloat
emission energy
- Returns
- countsarray
gaussian step peak
References
- 1
Rene Van Grieken, “Handbook of X-Ray Spectrometry, Second Edition, (Practical Spectroscopy)”, CRC Press, 2 edition, pp. 182, 2007.
-
skbeam.diffraction.
process_to_q
(setting_angles, detector_size, pixel_size, calibrated_center, dist_sample, wavelength, ub, frame_mode=None)¶ This will compute the hkl values for all pixels in a shape specified by detector_size.
- Parameters
- setting_anglesndarray
six angles of all the images - Required shape is [num_images][6] and required type is something that can be cast to a 2D numpy array Angle order: delta, theta, chi, phi, mu, gamma (degrees)
- detector_sizetuple
2 element tuple defining the number of pixels in the detector. Order is (num_columns, num_rows)
- pixel_sizetuple
2 element tuple defining the size of each pixel in mm. Order is (column_pixel_size, row_pixel_size). If not in mm, must be in the same units as dist_sample
- calibrated_centertuple
2 element tuple defining the center of the detector in pixels. Order is (column_center, row_center)(x y)
- dist_samplefloat
distance from the sample to the detector (mm). If not in mm, must be in the same units as pixel_size
- wavelengthfloat
wavelength of incident radiation (Angstroms)
- ubndarray
UB matrix (orientation matrix) 3x3 matrix
- frame_modestr, optional
Frame mode defines the data collection mode and thus the desired output from this function. Defaults to hkl mode (frame_mode=4) ‘theta’ : Theta axis frame. ‘phi’ : Phi axis frame. ‘cart’ : Crystal cartesian frame. ‘hkl’ : Reciprocal lattice units frame. See the process_to_q.frame_mode attribute for an exact list of valid options.
- Returns
- hklndarray
(Qx, Qy, Qz) - HKL values shape is [num_images * num_rows * num_columns][3]
Notes
Six angles of an image: (delta, theta, chi, phi, mu, gamma ) These axes are defined according to the following references.
-
skbeam.diffraction.
hkl_to_q
(hkl_arr)¶ This module compute the reciprocal space (q) values from known HKL array for each pixel of the detector for all the images
- Parameters
- hkl_arrndarray
(Qx, Qy, Qz) - HKL array shape is [num_images * num_rows * num_columns][3]
- Returns
- q_valndarray
Reciprocal values for each pixel for all images shape is [num_images * num_rows * num_columns]
-
skbeam.diffraction.
bin_1D
(x, y, nx=None, min_x=None, max_x=None)¶ Bin the values in y based on their x-coordinates
- Parameters
- xarray
position
- yarray
intensity
- nxinteger, optional
number of bins to use defaults to default bin value
- min_xfloat, optional
Left edge of first bin defaults to minimum value of x
- max_xfloat, optional
Right edge of last bin defaults to maximum value of x
- Returns
- edgesarray
edges of bins, length nx + 1
- valarray
sum of values in each bin, length nx
- countarray
The number of counts in each bin, length nx
-
skbeam.diffraction.
bin_edges
(range_min=None, range_max=None, nbins=None, step=None)¶ Generate bin edges. The last value in the returned array is the right edge of the last bin, the rest of the values are the left edges of each bin.
If range_max is specified all bin edges will be less than or equal to it’s value.
If range_min is specified all bin edges will be greater than or equal to it’s value
If nbins is specified then there will be than number of bins and the returned array will have length nbins + 1 (as the right most edge is included)
If step is specified then bin width is approximately step (It is not exact due to the nature of floats). The arrays generated by np.cumsum(np.ones(nbins) * step) and np.arange(nbins) * step are not identical. This function uses the second method in all cases where step is specified.
Warning
If the set
(range_min, range_max, step)
is given there is no guarantee thatrange_max - range_min
is an integer multiple ofstep
. In this case the left most bin edge isrange_min
and the right most bin edge is less thanrange_max
and the distance between the right most edge andrange_max
is not greater thanstep
(this is the same behavior as the built-inrange()
). It is not recommended to specify bins in this manner.- Parameters
- range_minfloat, optional
The minimum value that may be included as a bin edge
- range_maxfloat, optional
The maximum value that may be included as a bin edge
- nbinsint, optional
The number of bins, if specified the length of the returned value will be nbins + 1
- stepfloat, optional
The step between the bins
- Returns
- edgesnp.array
An array of floats for the bin edges. The last value is the right edge of the last bin.
-
skbeam.diffraction.
bin_edges_to_centers
(input_edges)¶ Helper function for turning a array of bin edges into an array of bin centers
- Parameters
- input_edgesarray-like
N + 1 values which are the left edges of N bins and the right edge of the last bin
- Returns
- centersndarray
A length N array giving the centers of the bins
-
skbeam.diffraction.
grid3d
(q, img_stack, nx=None, ny=None, nz=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, binary_mask=None)¶ Grid irregularly spaced data points onto a regular grid via histogramming
This function will process the set of reciprocal space values (q), the image stack (img_stack) and grid the image data based on the bounds provided, using defaults if none are provided.
- Parameters
- qndarray
(Qx, Qy, Qz) - HKL values - Nx3 array
- img_stackndarray
Intensity array of the images dimensions are: [num_img][num_rows][num_cols]
- nxint, optional
Number of voxels along x
- nyint, optional
Number of voxels along y
- nzint, optional
Number of voxels along z
- xminfloat, optional
Minimum value along x. Defaults to smallest x value in q
- yminfloat, optional
Minimum value along y. Defaults to smallest y value in q
- zminfloat, optional
Minimum value along z. Defaults to smallest z value in q
- xmaxfloat, optional
Maximum value along x. Defaults to largest x value in q
- ymaxfloat, optional
Maximum value along y. Defaults to largest y value in q
- zmaxfloat, optional
Maximum value along z. Defaults to largest z value in q
- binary_maskndarray, optional
The binary mask provides a mechanism to remove unwanted pixels from the images. Binary mask can be two different shapes. - 1: 2-D with binary_mask.shape == np.asarray(img_stack[0]).shape - 2: 3-D with binary_mask.shape == np.asarray(img_stack).shape
- Returns
- meanndarray
intensity grid. The values in this grid are the mean of the values that fill with in the grid.
- occupancyndarray
The number of data points that fell in the grid.
- std_errndarray
This is the standard error of the value in the grid box.
- boundslist
tuple of (min, max, step) for x, y, z in order: [x_bounds, y_bounds, z_bounds]
-
skbeam.diffraction.
q_to_d
(q)¶ Helper function to convert \(d\) to \(q\). The point of this function is to prevent fat-fingered typos.
By definition the relationship is:
\[q = \frac{2 \pi}{d}\]- Parameters
- qarray
An array of q values
- Returns
- darray
An array of d (plane) spacing in the inverse of the units of
q
-
skbeam.diffraction.
d_to_q
(d)¶ Helper function to convert \(d\) to \(q\). The point of this function is to prevent fat-fingered typos.
By definition the relationship is:
\[d = \frac{2 \pi}{q}\]- Parameters
- darray
An array of d (plane) spacing
- Returns
- qarray
An array of q values in the inverse of the units of
d
-
skbeam.diffraction.
q_to_twotheta
(q, wavelength)¶ Helper function to convert q to two-theta.
By definition the relationship is:
\[\sin\left(\frac{2\theta}{2}\right) = \frac{\lambda q}{4 \pi}\]thus
\[2\theta_n = 2 \arcsin\left(\frac{\lambda q}{4 \pi}\right)\]- Parameters
- qarray
An array of \(q\) values
- wavelengthfloat
Wavelength of the incoming x-rays
- Returns
- two_thetaarray
An array of \(2\theta\) values in radians
-
skbeam.diffraction.
twotheta_to_q
(two_theta, wavelength)¶ Helper function to convert two-theta to q
By definition the relationship is
\[\sin\left(\frac{2\theta}{2}\right) = \frac{\lambda q}{4 \pi}\]thus
\[q = \frac{4 \pi \sin\left(\frac{2\theta}{2}\right)}{\lambda}\]- Parameters
- two_thetaarray
An array of \(2\theta\) values
- wavelengthfloat
Wavelength of the incoming x-rays
- Returns
- qarray
An array of \(q\) values in the inverse of the units of
wavelength
-
skbeam.diffraction.
angle_grid
(center, shape, pixel_size=None)¶ Make a grid of angular positions.
Read note for our conventions here – there be dragons!
- Parameters
- centertuple
point in image where r=0; may be a float giving subpixel precision. Order is (rr, cc).
- shape: tuple
Image shape which is used to determine the maximum extent of output pixel coordinates. Order is (rr, cc).
- Returns
- agridarray
angular position (in radians) of each array element in range [-pi, pi]
-
skbeam.diffraction.
radial_grid
(center, shape, pixel_size=None)¶ Convert a cartesian grid (x,y) to the radius relative to some center
- Parameters
- centertuple
point in image where r=0; may be a float giving subpixel precision. Order is (rr, cc).
- shapetuple
Image shape which is used to determine the maximum extent of output pixel coordinates. Order is (rr, cc).
- pixel_sizesequence, optional
The physical size of the pixels. len(pixel_size) should be the same as len(shape) defaults to (1,1)
- Returns
- rarray
The distance of each pixel from center Shape of the return value is equal to the shape input parameter
-
skbeam.diffraction.
refine_center
(image, calibrated_center, pixel_size, phi_steps, max_peaks, thresh, window_size, nx=None, min_x=None, max_x=None)¶ Refines the location of the center of the beam.
This relies on being able to see the whole powder pattern.
- Parameters
- imagendarray
The image
- calibrated_centertuple
(row, column) the estimated center
- pixel_sizetuple
(pixel_height, pixel_width)
- phi_stepsint
How many regions to split the ring into, should be >10
- max_peaksint
Number of rings to look it
- threshfloat
Fraction of maximum peak height
- window_sizeint, optional
The window size to use (in bins) to use when refining peaks
- nxint, optional
Number of bins to use for radial binning
- min_xfloat, optional
The minimum radius to use for radial binning
- max_xfloat, optional
The maximum radius to use for radial binning
- Returns
- calibrated_centertuple
The refined calibrated center.
-
skbeam.diffraction.
estimate_d_blind
(name, wavelength, bin_centers, ring_average, window_size, max_peak_count, thresh)¶ Estimate the sample-detector distance
Given a radially integrated calibration image return an estimate for the sample-detector distance. This function does not require a rough estimate of what d should be.
For the peaks found the detector-sample distance is estimated via
\[D = \frac{r}{\tan 2\theta}\]where \(r\) is the distance in mm from the calibrated center to the ring on the detector and \(D\) is the distance from the sample to the detector.
- Parameters
- namestr
The name of the calibration standard. Used to look up the expected peak location
Valid options: [‘Al2O3’, ‘CeO2’, ‘LaB6’, ‘Ni’, ‘Si’]
- wavelengthfloat
The wavelength of scattered x-ray in nm
- bin_centersarray
The distance from the calibrated center to the center of the ring’s annulus in mm
- ring_averagearray
The average intensity in the given ring of a azimuthally integrated powder pattern. In counts [arb]
- window_sizeint
The number of elements on either side of a local maximum to use for locating and refining peaks. Candidates are identified as a relative maximum in a window sized (2*window_size + 1) and the same window is used for fitting the peaks to refine the location.
- max_peak_countint
Use at most this many peaks
- threshfloat
Fraction of maximum peak height
- Returns
- dist_samplefloat
The detector-sample distance in mm. This is the mean of the estimate from all of the peaks used.
- std_dist_samplefloat
The standard deviation of d computed from the peaks used.