diffractem.proc_peaks module¶
- class diffractem.proc_peaks.Cell(a=1, b=1, c=1, alpha=90, beta=90, gamma=90, lattice_type='triclinic', centering='P', unique_axis='c', d_min=2)[source]¶
Bases:
objectPartially taken from the PyFAI package, with some simplifications and speed enhancements for d-spacing calculation, as well as a new refinement function.
Calculates d-spacings and cell volume as described in: http://geoweb3.princeton.edu/research/MineralPhy/xtalgeometry.pdf
- property centering¶
- ctr_types = {'C': 'Side centered', 'F': 'Face centered', 'I': 'Body centered', 'P': 'Primitive', 'R': 'Rhombohedral'}¶
- classmethod cubic(a, centering='P')[source]¶
Factory for cubic lattice_types
- Parameters:
a – unit cell length
- d(d_min=None, unique=False, a=None, b=None, c=None, alpha=None, beta=None, gamma=None)[source]¶
Calculates d-spacings for the cell. Cell parameters can transiently be changed, which does not affect the values stored with the cell object. This is useful in the context of optimization.
- Parameters:
d_min (float, optional) – Minimum d-spacing. If None, uses the stored value of the object which can be set using init_hkl. Leaving it at None significantly speeds up the computation, which is recommended for refinements. Defaults to None.
unique (bool, optional) – if True, only unique d-spacings are returned. Otherwise, all spacings are returned which are ordered the same way as in the object’s hkl attribute. Defaults to False.
a (float, optional) – Temporary cell length. Defaults to None.
b (float, optional) – Temporary cell length. Defaults to None.
c (float, optional) – Temporary cell length. Defaults to None.
alpha (float, optional) – Temporary cell angle. Defaults to None.
beta (float, optional) – Temporary cell angle. Defaults to None.
gamma (float, optional) – Temporary cell angle. Defaults to None.
- Returns:
Array of d-spacings
- Return type:
np.array
- d_spacing(d_min=None, unique=False, a=None, b=None, c=None, alpha=None, beta=None, gamma=None)¶
Calculates d-spacings for the cell. Cell parameters can transiently be changed, which does not affect the values stored with the cell object. This is useful in the context of optimization.
- Parameters:
d_min (float, optional) – Minimum d-spacing. If None, uses the stored value of the object which can be set using init_hkl. Leaving it at None significantly speeds up the computation, which is recommended for refinements. Defaults to None.
unique (bool, optional) – if True, only unique d-spacings are returned. Otherwise, all spacings are returned which are ordered the same way as in the object’s hkl attribute. Defaults to False.
a (float, optional) – Temporary cell length. Defaults to None.
b (float, optional) – Temporary cell length. Defaults to None.
c (float, optional) – Temporary cell length. Defaults to None.
alpha (float, optional) – Temporary cell angle. Defaults to None.
beta (float, optional) – Temporary cell angle. Defaults to None.
gamma (float, optional) – Temporary cell angle. Defaults to None.
- Returns:
Array of d-spacings
- Return type:
np.array
- classmethod diamond(a)[source]¶
Factory for Diamond type FCC like Si and Ge
- Parameters:
a – unit cell length
- classmethod hexagonal(a, c, centering='P')[source]¶
Factory for hexagonal lattice_types
- Parameters:
a – unit cell length
c – unit cell length
- init_hkl(d_min=5.0)[source]¶
Sets up a grid with valid Miller indices for this lattice. Useful to pre-compute the indices before running any optimization, which speeds up the computation.
- Parameters:
d_min (float, optional) – Minimum d-spacing, in A. Defaults to 5.
- lattices = ['cubic', 'tetragonal', 'hexagonal', 'rhombohedral', 'orthorhombic', 'monoclinic', 'triclinic']¶
- classmethod monoclinic(a, b, c, beta, centering='P')[source]¶
Factory for hexagonal lattice_types
- Parameters:
a – unit cell length
b – unit cell length
c – unit cell length
beta – unit cell angle
- classmethod orthorhombic(a, b, c, centering='P')[source]¶
Factory for orthorhombic lattice_types
- Parameters:
a – unit cell length
b – unit cell length
c – unit cell length
- refine_powder(svec, pattern, method='distance', fill=0.1, min_prom=0.0, min_height=0.0, weights='prom', length_bound=2.0, angle_bound=3.0, **kwargs)[source]¶
Refine unit cell parameters against a powder pattern. The refinement is done using a least-squares fit, where you can pick three different cost functions:
- ‘distance’: the positions of the peaks in the powder pattern
are detected. For each peak, the distance to the closest d-spacing is computed.
- ‘xcorr’: the inverse values of the powder pattern at the
d-spacings are computed.
- ‘derivative’: the derivative of the powder pattern at the
d-spacings are computed
Depending on the chosen method, further parameters can be set. The function returns a new Cell object with refined parameters, and a structure with some useful information.
- Parameters:
svec (np.ndarray) – scattering vector (x-axis) of the powder pattern, expressed in inverse nanometer (not angstrom - following CrystFEL convention).
pattern (np.ndarray) – powder pattern at values svec (y-axis)
method (str, optional) – Cost function. See description. Defaults to ‘distance’.
fill (float, optional) – Fill value for out-of-range or zero-count s-vectors if method is ‘derivative’ or ‘xcorr’. Defaults to 0.1.
min_prom (float, optional) – Minimum prominence of peaks (that is, height relative to its vicinity) if method is ‘distance’. Increase if too many small peaks are spuriously detected. Usually it is a good idea. Defaults to 0.
min_height (float, optional) – Minimum peak height to be detected. Usually min_prom is the better parameter. Defaults to 0.
weights (str, optional) – Weights of the peaks for the least-squares optimization if method is ‘derivative’. Can be ‘prom’ or ‘height’. Defaults to ‘prom’.
length_bound (float, optional) – Bound range for cell lengths, in A. Defaults to 2.
angle_bound (float, optional) – Bound range for cell angles. Defaults to 3.
**kwargs – Further arguments will be passed on to scipy.least_sqaures
- Returns:
- 2-Tuple of a new Cell object with the refined parameters, and
a structure with useful information from the optimization, including the peak positions and heights if method was ‘distance’.
- Return type:
tuple
- classmethod rhombohedral(a, alpha, centering='P')[source]¶
Factory for hexagonal lattice_types
- Parameters:
a – unit cell length
alpha – unit cell angle
- selection_rules¶
contains a list of functions returning True(allowed)/False(forbidden)/None(unknown)
- classmethod tetragonal(a, c, centering='P')[source]¶
Factory for tetragonal lattice_types
- Parameters:
a – unit cell length
c – unit cell length
- property volume¶
- diffractem.proc_peaks.center_friedel(peaks, shots=None, p0=(778, 308), colnames=('fs/px', 'ss/px'), sigma=2, minpeaks=4, maxres=None)[source]¶
- [Center refinement of diffraction patterns from a list of peaks, assuming the presence
of a significant number of Friedel mates.]
- Parameters:
set (peaks {[pd.DataFrame]} -- [peaks list for entire data) –
convention!] (as returned by StreamParser. CrystFEL) –
- Keyword Arguments:
(default (maxres {int} -- [maximum radius of peaks to still be considered]) – {None})
(default – {(778, 308)})
(default – {(‘fs/px’, ‘ss/px’)})
radius (sigma {int} -- [peak rms) – {2})
(default – {4})
(default – {None})
- diffractem.proc_peaks.get_acf(npk, x, y, I=None, roi_length=512, output_radius=256, oversample=4, radial=True, px_ang=None, execution='processes')[source]¶
Gets the autocorrelation/pair correlation function of Bragg peak positions, optionally with intensity weighting.
It is important to set the computation region properly (i.e., the maximum peak positions from the center to take into account), as this affects computation speed and impact of non-paraxiality at larger angles. It can be defined using the roi_length argument.
Peaks must be given in CXI format.
- Parameters:
npk (np.ndarray, int) – number of peaks
x (np.ndarray) – x-coordinates of peaks, relative to pattern center
y (np.ndarray) – y-coordinates of peaks, relative to pattern center
I ([type], optional) – peak intensities. Set to 1 if None. Defaults to None.
roi_length (int, optional) – edge length of the region around the image center that is used for the computation. Defaults to 512.
output_radius (int, optional) – maximum included radius of the output ACF. The size of the 2D output will be 2*output_radius*oversample, the size of the radial average will be output_radius*oversample. Defaults to 600.
oversample (int, optional) – oversampling, that is, by how much smaller the bin sizes of the output are than that of the input (usually the pixels). Defaults to 4.
radial (bool, optional) – compute the radial average of the ACF. Defaults to True.
px_ang (double, optional) – diffraction angle corresponding to a distance of 1 pixel from the center, given in rad (practically: detector pixel size/cam length). If given, non-paraxiality of the geometry is corrected (not tested well yet). Defaults to None.
execution (str, optional) – way of parallelism if a stack of pattern peak data is supplied. Can be ‘single-threaded’, ‘threads’, ‘processes’.
- Returns:
- 2D autocorrelation function.
Length will be 2 * oversample * output_range
- np.ndarray: 1D radial sum (None for radial=False).
Length will be oversample * output_ramge
- Return type:
np.ndarray