datad package¶
datad.atom module¶
-
class
datad.atom.
Atom
(name: AnyStr)¶ Bases:
object
- Parameters
name (string) – Name of element. These names are all legal to initialize a Cu atomion:
'cu'
,'Cu'
,'CU'
,'Cu+'
,'Cu-'
and'Cu2+'
. If the name is illegal, a ValueError will be raised.
-
approximate_scattering_factors_electron
()¶ Returns approximate atomic scattering factors for electron.
Here the sum of parameters Ai in scattering factor is returned.
See also
-
approximate_scattering_factors_xray
()¶ Returns approximate atomic scattering factors for xray.
Here parameter C is returned.
See also
-
property
name
¶ Name of
Atom
-
property
scattering_factor_coeffs_electron
¶ Coefficients of atomic scattering factor for electron.
- Returns
parameters – Parameters constisting of two 5-element array of float
- Return type
tuple
-
property
scattering_factor_coeffs_xray
¶ Parameters of the atomic scattering factor for xray.
- Returns
parameters – Parameters constisting of two 4-element array of float and one float
- Return type
tuple
-
scattering_factors_electron
(tths: Iterable[float], wls: Iterable[float], *, is_degree: bool = False) → numpy.ndarray¶ Calculate atomic scattering factor for monochromatic electron scattered to specific scattering angle.
- Parameters
tths (array-like of float) – Scattering angles, 2heta
wls (array-like of float) – Wavelengths of electron in Angstrom
is_degree (bool, optional) – If True, scattering angles are in degrees, otherwise in radians. The default value is False.
- Returns
factor – atomic scattering factors
- Return type
array of float
See also
scattering_factor_xray
scattering factors for xray
-
scattering_factors_for_rcp_vectors_electron
(rcp_vecs: Union[Iterable[Union[int, float]], Iterable[Iterable[Union[int, float]]]]) → numpy.ndarray¶ Calculate atomic scattering factor for monochromatic xray scattered with specific scattering vectors.
- Parameters
rcp_vecs (3-element vector or an array of 3-element vectors) – vectors in reciprocal space, a.k.a. scattering vectors
- Returns
factors – atomic scattering factor(s)
- Return type
array of float
-
scattering_factors_for_rcp_vectors_xray
(rcp_vecs: Union[Iterable[Union[int, float]], Iterable[Iterable[Union[int, float]]]]) → numpy.ndarray¶ Calculate atomic scattering factor for monochromatic xray scattered at specific scattering vectors.
- Parameters
rcp_vecs (3-element vector or an array of 3-element vectors) – vectors in reciprocal space, a.k.a. scattering vectors
- Returns
factors – atomic scattering factor(s)
- Return type
array of float
-
scattering_factors_xray
(tths: Iterable[float], wls: Iterable[float], *, is_degree: bool = False) → numpy.ndarray¶ Calculate atomic scattering factor for monochromatic xray scattered to specific scattering angle.
- Parameters
tths (array-like of float) – Scattering angles, 2θ.
wls (array-like of float) – Wavelengths of x-ray in Angstrom.
is_degree (bool, optional) – If True, scattering angles are in degrees, otherwise in radians. The default value is False.
- Returns
factor – atomic scattering factors
- Return type
array of float
See also
scattering_factor_electron
scattering factors for electron
-
class
datad.atom.
AtomInCell
(element: AnyStr, atomcoor: Union[datad.atom.FracCoor, Iterable[Union[int, float]]])¶ Bases:
datad.atom.Atom
Atom with its fractional coordinates in a unit cell.
-
property
x
¶ First coordinate
-
property
y
¶ Second coordinate
-
property
z
¶ Third coordinate
-
property
-
class
datad.atom.
AtomsInCell
¶ Bases:
object
Collection of AtomInCell used for iteration.
-
add
(atom: datad.atom.AtomInCell, *, sort: bool = False) → datad.atom.AtomsInCell¶ Add an atom to this collection. This function can be invoked chainingly like:
atomsInCell.add(...).add(...)
- Parameters
atom (AtomInCell) – atom to be added
sort (bool, optional) – If True, the atoms are sorted after inserting. The default value is False.
- Returns
atomsInCell –
AtomsInCell
with given atom added.- Return type
-
approximate_scattering_factors_electron
()¶ Return the approximate scattering factors for electron of all atoms in this collection.
- Returns
factors – Approximate scattering factors.
- Return type
array of float
-
approximate_scattering_factors_xray
()¶ Return the approximate scattering factors for xray of all atoms in this collection.
- Returns
factors – Approximate scattering factors.
- Return type
array of float
-
coors
()¶ Coordiantes of all atoms in this collection
- Returns
coors – Coordinates of atoms. N is the number of atoms in this collection.
- Return type
array of float with size
N*3
-
static
from_array
(a: Iterable[Tuple[AnyStr, Iterable[Union[int, float]]]]) → datad.atom.AtomsInCell¶ Initialize AtomsInCell by an array
- Parameters
a (array-like) – an array of serialized atom information. The element of
a
is 2-element array-like; first is a stringrepresenting element and second is a 3-element float array-like representing fractional coordinates.- Returns
atoms
- Return type
-
scattering_factors_electron
(tths: Iterable[float], wls: Iterable[float], *, is_degree: bool = False) → numpy.ndarray¶ Calculate scattering factors for electron of all atoms in this collection.
- Parameters
tths (array-like with size
N
) – List of scattering angles, i.e. :math:2theta.wls (array-like with size
N
) – List of wavelengths of xray in Angstrom.is_degree (bool, optional) – If True,
tths
will be in degrees, otherwise in radian. The default value is False.
- Returns
factors – Scattering factors of all atoms in this collection.
M
denotes the number of atoms- Return type
array-like with size
M * N
See also
scattering_factors_xray
scattering factors for xray
-
scattering_factors_for_rcp_vectors_electron
(rcp_vecs: Union[Iterable[Union[int, float]], Iterable[Iterable[Union[int, float]]]]) → numpy.ndarray¶ Calculate scattering factors for electron of all atoms in this collection.
- Parameters
rcp_vecs (vector or an array-like of vectors) – reciprocal vector(s) Shape is (3,), (N,3) or (M,N,3)
- Returns
factors – Scattering factors of all atoms in this collection.
A
denotes the number of atoms.- Return type
array of floats with size (N,A) or (M,N,A)
-
scattering_factors_for_rcp_vectors_xray
(rcp_vecs: Union[Iterable[Union[int, float]], Iterable[Iterable[Union[int, float]]]]) → numpy.ndarray¶ Calculate scattering factors for xray of all atoms in this collection.
- Parameters
rcp_vecs (vector or an array-like of vectors) – reciprocal vector(s) shape is (3,), (N,3) or (M,N,3)
- Returns
factors – Scattering factors of all atoms in this collection.
A
denotes the number of atoms.- Return type
array of floats with size (N,A) or (M,N,A)
-
scattering_factors_xray
(tths: Iterable[float], wls: Iterable[float], *, is_degree: bool = False) → numpy.ndarray¶ Calculate scattering factors for xray of all atoms in this collection.
- Parameters
tths (array-like with size
N
) – List of scattering angles, i.e. 2θwls (array-like with size
N
) – List of wavelengths of xray in Angstromis_degree (bool, optional) – If true, the
tths
will be in degrees, otherwise in radian. Default False
- Returns
factors – Scattering factors of all atoms in this collection.
M
denotes the number of atoms- Return type
array-like with size
M * N
See also
scattering_factors_electron
scattering factors for electron
-
sort
()¶ Sort the atoms in AtomsInCell ascendingly
-
-
class
datad.atom.
AtomsIterator
(atoms: datad.atom.AtomsInCell)¶ Bases:
object
AtomsInCell iterator class
-
class
datad.atom.
FracCoor
(v)¶ Bases:
numpy.ndarray
Fractional coordinates atom’s position in unit cell. The coordinates is 3-dimensional and each element is between 0 and 1
-
property
x
¶
-
property
y
¶
-
property
z
¶
-
property
-
datad.atom.
reg
(name: AnyStr) → AnyStr¶ Recognize name of element and return corresponding regular name
If name is not a element name, a ValueError will be raised.
- Parameters
name (str) – Original name
- Returns
out – regular name
- Return type
str
datad.cylindricalDetector module¶
-
class
datad.cylindricalDetector.
CylindricalDetector
(*, normal: Iterable[Union[int, float]], sizex: Union[int, float], sizey: Union[int, float], dist: Union[int, float], ponix: Union[int, float], poniy: Union[int, float], radius: Union[int, float], ps: Union[int, float] = None, start_angle: Union[int, float] = 0, vx: Iterable[Union[int, float]] = None, vy: Iterable[Union[int, float]] = None, is_degree: bool = True)¶ Bases:
datad.detector.Detector
Cylindrical detector which is attached to the side surface of a cylinder.
- Parameters
normal (vector) – Normal direction.
sizex (number) – Size along the x-axis of detector.
sizey (number) – Size along the y-axis of detector.
dist (number) – Sample-to-PONI distance.
ponix (number) – x coordinate of PONI
poniy (number) – y coordiante of PONI
radius (number) – Radius of cylinder
vx (vector, optional) – Direction of x-axis of the detector in sample coordinate system.
vy (vector, optional) – Direction of y-axis of the detector in sample coordinate system.
start_angle (number, optional) – Azimuthal angle of the detector origin on the base plane default 0 degree
is_degree (bool, optional) – If True, the input angles are in degrees, otherwise in radians. The default value is True.
-
calc_tthgam_map
(*, inc: Optional[Iterable[Union[int, float]]] = None, vx: Optional[Iterable[Union[int, float]]] = None)¶ Calculate the map of 2θ−γ on the cylindrical detector.
- Parameters
inc (vector, optional) – Incident direction. The default direciton is the reverse normal direction of this detector.
vx (vector, optional) – Transverse direction with zero azimuthal angle The default direction is the x-axis of this detector.
-
generate_positions
(ps: Optional[Union[int, float]] = None) → Tuple[Iterable[Union[int, float]], Iterable[Union[int, float]]]¶ Generate the positions of pixels on detector.
- Parameters
ps (number, optional) – pixel size of the detector. If the pixel size is specified at instantiation, the pixel size can not be specified here.
-
geometry_factor
(px: Iterable[Union[int, float]], py: Iterable[Union[int, float]]) → numpy.ndarray¶ Geometry factor
-
p_to_tthgam
(px: Iterable[Union[int, float]], py: Iterable[Union[int, float]], *, inc: Iterable[Union[int, float]] = (0, 0, - 1), vx: Iterable[Union[int, float]] = (1, 0, 0), is_degree: bool = False) → Tuple[numpy.ndarray, numpy.ndarray]¶ Map positions on cylindrical detector to 2θ−γ pair.
- Parameters
px (vectors) – Position along the x-axis of the detector.
py (vectors) – Position along the y-axis of the detector.
inc (vector, optional) – Incident direction. The default direction is the -z-axis in sample coordinate system.
vx (vector, optional) – Transverse direction with zero azimuthal angle. The default direction is the x-axis in sample coordinate system.
- Returns
tthgam – 2θ−γ pairs
- Return type
tuple
-
p_to_vectors
(px: Iterable[Union[int, float]], py: Iterable[Union[int, float]]) → numpy.ndarray¶ Map the coordinates in detector coordinates system to the vectors in sample coordinates system
- Parameters
px (vectors) – Position along x-axis of detector.
py (vectors) – Position along y-axis of detector.
- Returns
vectors – Vectors in sample coordinate system
- Return type
an array of vectors
-
show
(*, ax=None, show_label: bool = False, show_color: bool = True, show_direct: bool = False, show_poni: bool = True, **kwargs)¶ Plot to show the pattern on the detector
-
show_1d
(*, ax=None, show_label: bool = False, show_color: bool = True, show_direct: bool = False, show_poni: bool = True, **kwargs) → None¶ show 1d profile in detector
-
show_2d
(*, ax=None, show_label: bool = False, show_color: bool = True, show_direct: bool = False, show_poni: bool = True, **kwargs) → None¶ show 1d profile in detector
-
tthgam_to_p
(tths: Iterable[Union[int, float]], gammas: Iterable[Union[int, float]], *, is_degree: bool = False, inc: Optional[Iterable[Union[int, float]]] = None, vx: Optional[Iterable[Union[int, float]]] = None) → Tuple[numpy.ndarray, numpy.ndarray]¶ Map 2θ−γ pair to the coordinates on detector plane.
if coordinates cannot be calculated, np.nan will be returned.
- Parameters
tths (vector) – Scattering angles 2θ.
gammas (vector) – Azimuthal angles γ.
is_degree (bool, optional) – If True, the input angles are in degrees. The default value is False.
inc (vector, optional) – Incident direction in sample coordinates system. The default direciton is the reverse normal direction of this detector.
vx (vector, optional) – Transverse direction with zero azimuthal angle in sample coordinates system. The default direction is the x-axis of the detector.
- Returns
p – tuple of two lists containing x coordinate and y coordinate, respectively.
- Return type
a tuple of two array
datad.detector module¶
-
class
datad.detector.
Detector
(*, normal: Iterable[Union[int, float]], sizex: Union[int, float], sizey: Union[int, float], dist: Union[int, float], ponix: Union[int, float], poniy: Union[int, float], vx: Iterable[Union[int, float]] = None, vy: Iterable[Union[int, float]] = None, ps: Union[int, float] = None)¶ Bases:
object
Planar detector.
There are some coordinates systems which are easy to get confused with each others and here we are going to clarify them.
A coordinates system is established against the planar detector. Assume that the photosensitive surface of detector is the front side and the other side is the back side. The plane of detector can be treated as a 2D coordinates system in a 3D space. The x- and y-axis coincide with the two edge of rectangle detector detector, and z-axis is perpendicular to the plane. Note that the coordinates system should be right-handed. So the z-axis is set to point to the front size of detector and usually to the sample. The x- and y-axis always adapt to the alignment of pixel matrix. A common geometry is that the x-axis points to the right horizontally and y-axis points up vertically. The x- and y-axis is different from the image coordinates, in which x-axis points to the right horizontally and y-axis points down vertically. This will be carefully dealed at detector image.
The unit of length in Detector is arbitary. It can be micrometer, millimeter or centimeter. Note keeping the unit of length identical for different physical quantity.
- Parameters
normal (vector) – Normal direction of detector in sample coordinates system The normal direction is perpendicular to the detector plane and points from the backside of detector to the photosensitive side. The normal direction usually points to the sample in sample diffraction geometry.
sizex (number) – Size of detector along x-axis. Unit is arbitrary.
sizey (number) – Size of detector along y-axis. Unit is arbitrary.
dist (number) – Distance from detector front surface to the sample.
ponix (number) – Coordinate of PONI along the x-axis of detector.
poniy (number) – Cooridnate of PONI along the y-axis of detector.
vx (vector, opitional) – x-axis of detector in sample coordinate system. They should be perpendicular to the normal direction. The x-axis is perpendicular to the normal direction and lies on the xy-plane of experiemental coordinates system default and the y-axis can be derived from x-axis and normal direction. Not all of these x- and y-axis need given together, one of them can be derived from the other by the normal direction.
vy (vector, optional) – y-axis of detector in sample coordinate system.
ps (number, optional) – Pixel size.
-
calc_index
(px: Iterable[Union[int, float]], py: Iterable[Union[int, float]]) → Tuple[Iterable[Union[int, float]], Iterable[Union[int, float]]]¶
-
calc_to_pic
(ps: Union[int, float], show: bool = True, *args, **kwargs) → None¶ Calculate the intensities of each pixels.
- Parameters
ps (number, optional) – Pixel size
show (bool, optional) – If plotting the calculated picture. The default value is True.
-
calc_to_pic_1d
(tth_res: Union[int, float] = 0.1, *, is_degree: bool = True)¶ Calculate the intensities of each pixels after a 1D diffraction curve is projected.
- Parameters
tth_res (number, optional) – Resolution of 2θ. The default resolution is 0.1 degree.
is_degree (bool, optional) – If True, the input angles are in degrees, otherwise in radians. The default value is True.
-
calc_to_pic_2d
(*, sigmax: int = 1, sigmay: int = 1, rot_angle: Union[int, float] = 0, is_degree: bool = True)¶ Calculate the intensities of each pixels after a 2D diffraction pattern is projected.
- Parameters
sigmax (int) – Sigma (standard deviation) value of the Gaussian peak broadening along the first main axis. Unit is pixel. The default value is 1.
sigmay (int) – Sigma (standard deviation) value of the Gaussian peak broadening along the second main axis. Unit is pixel. The default value is 1.
rot_angle (number) – Angle between the main axes and the detector axes. The default angle is 0 degree.
is_degree (bool, optional) – If True, the input angles are in degrees, otherwise in radians. The default value is True.
-
calc_tthgam_map
(*, inc: Optional[Iterable[Union[int, float]]] = None, vx: Optional[Iterable[Union[int, float]]] = None)¶ Calculate the 2θ−γ pair map on the detector.
- Parameters
inc (vector, optional) – Incident direction in sample coordinates system. The default direciton is the reverse normal direction of this detector.
vx (vector, optional) – Transverse direction with zero azimuthal angle in sample coordinates system. The default direction is the x-axis of the detector.
-
change_pic_intensity_to_pic
()¶
-
geometry_factor
(px: Iterable[Union[int, float]], py: Iterable[Union[int, float]]) → numpy.ndarray¶ Geometry factor
-
init_pic
(ps: Optional[Union[int, float]] = None) → None¶ Initialize a picture with the same size of detector
Note that the y-axis of the picture is the reverse y-axis of detector.
- Parameters
ps (number, optional) – Pixel size of the picture. default the pixel size set in this detector If the pixel size is not set in detector and this ps is also not set, a ValueError will be raised
-
is_on_by_tthgam
(tths: Iterable[Union[int, float]], gammas: Iterable[Union[int, float]], *, is_degree: bool = False, inc: Optional[Iterable[Union[int, float]]] = None, vx: Optional[Iterable[Union[int, float]]] = None) → numpy.ndarray¶ determine whether the point is on the detector by 2θ−γ pair.
- Parameters
tths (vector) – Scattering angles 2θ.
gammas (vector) – Azimuthal angles γ.
is_degree (bool, optional) – If True, the input angles are in degrees. Otherwise the angles are in radians. The default value is False.
inc (vector, optional) – Incident direction in sample coordinates system. The default direciton is the reverse normal direction of this detector.
vx (vector, optional) – Transverse direction with zero azimuthal angle in sample coordinates system. The default direction is the x-axis of the detector.
- Returns
is_on – Whether the points are on detector.
- Return type
array of bool
-
is_on_by_xy
(px: Iterable[Union[int, float]], py: Iterable[Union[int, float]]) → numpy.ndarray¶ Determine whether the points are on the detector.
- Parameters
px (vector) – x coordinate
py (vector) – y coordinate
- Returns
array – Whether the points are on the detector.
- Return type
array of bool
-
is_peaks_on
() → bool¶ Whether any peaks are projected onto the detector
-
p_to_tthgam
(px: Iterable[Union[int, float]], py: Iterable[Union[int, float]], *, inc: Iterable[Union[int, float]] = (0, 0, - 1), vx: Iterable[Union[int, float]] = (1, 0, 0), is_degree: bool = False) → Tuple[numpy.ndarray, numpy.ndarray]¶ Map positions on cylindrical detector to 2θ−γ pair.
- Parameters
px (vectors) – Position along the x-axis of the detector.
py (vectors) – Position along the y-axis of the detector.
inc (vector, optional) – Incident direction. The default direction is the -z-axis of the sample coordinate system.
vx (vector, optional) – Transverse direction with zero azimuthal angle. The default direction is the x-axis of the sampel coordinate system.
- Returns
tthgam – 2θ−γ pairs
- Return type
tuple
-
p_to_vectors
(px: Iterable[Union[int, float]], py: Iterable[Union[int, float]]) → numpy.ndarray¶ Map the coordinates in detector coordinates system to the vectors in sample coordinates system
- Parameters
px (vectors) – Coordinate along the x-axis of the detector.
py (vectors) – Coordinate along the y-axis of the detector.
- Returns
vectors – Vectors in sample coordinate system
- Return type
an array of vectors
-
peak_found
(hkls: Union[datad.hkl.HKL, Iterable[datad.hkl.HKL]]) → Union[bool, Iterable[bool]]¶ Whether the peaks with given Miller index triplets are on the detector.
-
project_peaks
(simu: Union[datad.simu1d.Curve1D, datad.simu2d.Pattern2D], *, inc: Iterable[Union[int, float]] = (0, 0, - 1), vx: Iterable[Union[int, float]] = (1, 0, 0), **kwargs) → None¶ project the diffraction simulation result to the detector.
- Parameters
simu (Profile1D or Pattern2D) – Diffraction simulation result
-
project_peaks_1d
(simu1d: datad.simu1d.Curve1D, *, num_gammas: int = 2000) → None¶ Project the 1D diffraction curve onto the detector.
- Parameters
simu1d (Curve1D) – 1D diffraction curve.
num_gammas (int, optional) – Number of gammas increments. The default number of increments is 2000.
-
project_peaks_2d
(simu2d: datad.simu2d.Pattern2D) → None¶ Project 2D diffraction pattern onto the detector.
-
rotate_by
(axis: Iterable[Union[int, float]], angle: Union[int, float], *, is_degree: bool = True) → datad.detector.Detector¶ Rotate the detector.
This function only supports axis-angle notation.
- Parameters
axis (vector) – Rotation axis
angle (number) – Rotation angle
is_degree (bool, optional) – Whether the angle is in degree default True
- Returns
detector – Rotated detector
- Return type
-
save_pic
(filepath: str)¶ Save the picture to file at given path.
-
show
(*, ax=None, show_label: bool = False, show_color: bool = True, show_direct: bool = True, show_poni: bool = True, **kwargs)¶ Plot to show the pattern on detector.
- Parameters
ax (matplotlib axes, optional) – Axis to be plotted in. If not specified, a new axis will be created.
show_label (bool, optional) – Whether plotting the label. default False.
show_color (bool, optional) – Whether colorizing the points. default True.
show_direct (bool, optional) – Whether plotting the direct beam. default True.
show_poni (bool, optional) – Whether plotting the PONI. default True.
kwargs – all other keyword arguments will be passed to axis.scatter() during the plotting.
-
show_1d
(*, ax=None, show_label: bool = False, show_color: bool = True, show_direct: bool = True, show_poni: bool = True, **kwargs) → None¶ show 1d profile in detector
-
show_2d
(*, ax=None, show_label: bool = False, show_color: bool = True, show_direct: bool = True, show_poni: bool = True, **kwargs) → None¶ plot 2d pattern
-
property
size
¶ Size of detector, first one is along x-axis and the second one is along y-axis.
-
tthgam_to_p
(tths: Iterable[Union[int, float]], gammas: Iterable[Union[int, float]], *, is_degree: bool = False, inc: Optional[Iterable[Union[int, float]]] = None, vx: Optional[Iterable[Union[int, float]]] = None) → Tuple[numpy.ndarray, numpy.ndarray]¶ Map 2θ−γ pair to the coordinates on detector plane.
If coordinates cannot be calculated, np.nan will be returned.
- Parameters
tths (vector) – Scattering angles 2θ.
gammas (vector) – Azimuthal angles γ.
is_degree (bool, optional) – If True, the input angles are in degrees. Otherwise the angles are in radians. The default value is False.
inc (vector, optional) – Incident direction in sample coordinates system. The default direciton is the reverse normal direction of this detector.
vx (vector, optional) – Transverse direction with zero azimuthal angle in sample coordinates system. The default direction is the x-axis of the detector.
- Returns
p – Tuple of two lists containing x coordinate and y coordinate, respectively.
- Return type
a tuple of two array
datad.hkl module¶
-
class
datad.hkl.
HKL
(index0: Union[int, float], index1: Union[int, float], index2: Union[int, float])¶ Bases:
numpy.ndarray
Miller index triplet
-
class
datad.hkl.
HKLGroup
(vs: Union[datad.hkl.HKL, Iterable[datad.hkl.HKL]])¶ Bases:
datad.hkl.HKL
a group of HKLs
-
class
datad.hkl.
UVW
(v)¶ Bases:
numpy.ndarray
Lattice direction indices
-
datad.hkl.
create_index
(hklrange: Iterable[int] = (5, 5, 5), *, include_negative: bool = True) → Iterator[datad.hkl.HKL]¶ returns a group of miller index
- Parameters
hklrange (3-element array-like of int) – the range of hkl.
include_negative (bool, optional) – whether the negative indices are included default True
- Returns
hkls – an list of HKL
- Return type
array-like of HKL
datad.imgOnDetector module¶
-
class
datad.imgOnDetector.
ImgOnDetector
(detector: datad.detector.Detector, img: datad.maskedImg.MaskedImg, ps: Optional[Union[int, float]] = None)¶ Bases:
object
Image projected on a detector
- Parameters
detector (Detector) – Detector
img (MaskedImage) – Image
ps (number, optional) – Pixel size. If the pixel size is specified in detector, this pixel size is optional
-
Find_peaks
(threshold: Union[int, float], expansion: int = 1, *, model: lmfit.model.Model = None, areaLimit: int = 6)¶ Find the diffration spots on the image
- Parameters
threshold (number) – Threshold used in blobs finding. See find_blobs for details
expansion (int) – Expansion used in peaks finding. See find_peaks for details
model (Model) – lmfit Model used in peaks finding
areaLimit (int) – Area limit used in peaks finding
-
Save_peaks
(filename)¶ save the peaks to file
-
calc_map
(*, inc: Optional[Iterable[Union[int, float]]] = None, vx: Optional[Iterable[Union[int, float]]] = None)¶ Calculate 2θ−γ map of the pixels of the image.
-
incorporate_simu
(simu: Union[datad.simu1d.Curve1D, datad.simu2d.Pattern2D], *, inc: Iterable[Union[int, float]] = (0, 0, - 1), vx: Iterable[Union[int, float]] = (1, 0, 0)) → None¶ incorporate diffraction simulations to this
-
integrate
(*args, **kwargs)¶ Integrate diffraction pattern to 1D diffraction curve.
-
remove_bkg_brukner
(n: int = 5, max_iter: int = 5)¶ Remove background of image by brukner method. This method is extremely SLOW. THINK TWICE.
- Parameters
n (int, optional) – Range which the intensities is averaged over. Large n results in abstraction of low wide bragg peaks. default 5.
max_iter (int, optional) – Maximum iterative time default 5
-
remove_bkg_gaussian
(sigma: Union[int, float])¶ Remove background of image by gaussian filter.
- Parameters
sigma (number) – standard deviation for Gaussian kernel.
-
set_geometry
(inc: Iterable[Union[int, float]] = None, vx: Iterable[Union[int, float]] = None) → None¶ Set the diffraction geometry
- Parameters
inc (vector, optional) – Incidence direction of xray default the incidence direction in detector or the reverse normal direction of detector
vx (vector, optional) – Transverse direction with zero azimuthal angle default the x-axis in detector
-
show_img
(cmap='gray_r')¶ Plot the image.
-
show_in_tthgam
(*args, **kwargs)¶ Plot to show the picture in 2θ−γ space.
-
show_intergrated
(min_tth: Optional[Union[int, float]] = None, max_tth: Optional[Union[int, float]] = None, *, is_degree: bool = True, **kwargs)¶ Plot to show the intergrated 1D curve.
- Parameters
min_tth (number, optional) – Minimum of scattering angles to show
max_tth (number, optional) – Maximum of scattering angles to show
is_degree (bool, optional) – Whether the input angle is in degree default True.
-
show_map
(size: Union[int, float] = 0.1)¶ Plot to show the map of 2θ−γ of the image.
-
show_with_simu
(cmap='gray_r', **kwargs)¶ Plot the image along with the simulation results.
-
datad.imgOnDetector.
integrate
(iods: Iterable[datad.imgOnDetector.ImgOnDetector], tth_res: Union[int, float] = 0.1, min_2th: Optional[Union[int, float]] = None, max_2th: Optional[Union[int, float]] = None, min_gamma: Optional[Union[int, float]] = None, max_gamma: Optional[Union[int, float]] = None, *, file: str = None, smooth: bool = False, win_len: int = 31, is_degree: bool = True) → Tuple[numpy.ndarray, numpy.ndarray]¶ Integrate diffraction pattern to 1D curve
- Parameters
iods (an array-like of ImgOnDetector) – List of ImgOnDetector to be integrated
tth_res (number) – Resolution of integrated scattering angles
min_2th (number, optional) – Minimum of the integrated scattering angles
max_2th (number, optional) – Maximum of the integrated scattering angles
min_gamma (number, optional) – Minimum of gamma to be integrated
max_gamma (number, optional) – Maximum of gamma to be integrated
file (str, optional) – if specified, the integration results will be output into this file.
smooth (bool, optional) – Whether the integration will be smoothed. default False.
win_len (int, optional) – Window length used in smoothing. default 31.
is_degree (bool, optional) – Whether the input angles are in degree. default True.
- Returns
result – Scattering angles and the associated intensities.
- Return type
tuple of two array
-
datad.imgOnDetector.
save_tthgam
(fname: str, iods: Iterable[datad.imgOnDetector.ImgOnDetector])¶ Save the 2θ−γ map to file.
- Parameters
fname (string) – Filename.
iods (an array of ImgOnDetector) – image(s) to be saved.
-
datad.imgOnDetector.
show_in_tthgam
(iods: Iterable[datad.imgOnDetector.ImgOnDetector], min_2th: Optional[Union[int, float]] = None, max_2th: Optional[Union[int, float]] = None, min_gamma: Optional[Union[int, float]] = None, max_gamma: Optional[Union[int, float]] = None, *, size: Union[int, float] = 0.1, cmap: str = 'jet', vmin: Optional[Union[int, float]] = None, vmax: Optional[Union[int, float]] = None, is_degree: bool = True, **kwargs)¶ Plot the images on detectors to the 2θ−γ space.
- Parameters
iods (an array-like of ImgOnDetector) – List of ImgOnDetector to be integrated
min_2th (number, optional) – Minimum of the integrated scattering angles
max_2th (number, optional) – Maximum of the integrated scattering angles
min_gamma (number, optional) – Minimum of gamma to be integrated
max_gamma (number, optional) – Maximum of gamma to be integrated
size (number) – Size of scatter
cmap (str, optional) – Color map used to plot the image. default ‘jet’.
vmin (number, optional) – Min and max value used in color map. default None.
vmax (number, optional) – Min and max value used in color map. default None.
is_degree (bool, optional) – Whether the input angles are in degrees. default True.
-
datad.imgOnDetector.
smoothFunc
(x, window_len=11, window='hanning')¶ smooth the data using a window with requested size.
This method is based on the convolution of a scaled window with the signal. The signal is prepared by introducing reflected copies of the signal (with the window size) in both ends so that transient parts are minimized in the begining and end part of the output signal.
- Parameters
x (the input signals) –
window_len – the dimension of the smoothing window; should be an odd integer
window – the type of window from ‘flat’, ‘hanning’, ‘hamming’, ‘bartlett’, ‘blackman’ flat window will produce a moving average smoothing.
datad.latticeparameters module¶
-
class
datad.latticeparameters.
LatticeParameters
(direct_matrix)¶ Bases:
object
Lattice Parameters
- Parameters
lattice_matrix (3*3 matrix) – Lattice matrix, consisting of three ROW primitive vectors.
-
property
a
¶ First lattice parameter
-
alpha
(is_degree: bool = True) → float¶ Angle between lattice base vector b and c
- Parameters
is_degree (bool, optional) – If true, angle will be in degree, otherwise in radian. Default True
-
property
b
¶ Second lattice parameter
-
beta
(is_degree: bool = True) → float¶ Angle between lattice base vector a and c
- Parameters
is_degree (bool, optional) – If true, angle will be in degree, otherwise in radian. Default True
-
property
c
¶ Third lattice parameter
-
property
direct_matrix
¶ Direct matrix consisting of three ROW primitive vectors.s
-
static
from_basevectors
(a: List[Union[int, float]], b: List[Union[int, float]], c: List[Union[int, float]]) → datad.latticeparameters.LatticeParameters¶ Return
LatticeParameters
from three primitive vectors- Parameters
a (3-element array-like) – Three primitive vectors
b (3-element array-like) – Three primitive vectors
c (3-element array-like) – Three primitive vectors
- Returns
lp
- Return type
-
static
from_parameters
(a: Union[int, float], b: Union[int, float], c: Union[int, float], alpha: Union[int, float], beta: Union[int, float], gamma: Union[int, float], is_degree: bool = True) → datad.latticeparameters.LatticeParameters¶ Return
LatticeParameters
from six lattice parameters.- Parameters
a (real number) – Lengths of basic vectors. Units are Angstrom
b (real number) – Lengths of basic vectors. Units are Angstrom
c (real number) – Lengths of basic vectors. Units are Angstrom
alpha (real number.) – Angles between basic vectors.
beta (real number.) – Angles between basic vectors.
gamma (real number.) – Angles between basic vectors.
is_degree (bool, optional) – If true,
alpha
,beta
andgamma
are in degrees, otherwise in radians. Default true
- Returns
lp
- Return type
-
gamma
(is_degree: bool = True) → float¶ Angle between lattice base vector a and b
- Parameters
is_degree (bool, optional) – If true, angle will be in degree, otherwise in radian. Default True
-
property
rcp_matrix
¶ Reciprocal matrix consisting of three ROW reciprocal primitive vectors.
datad.maskedImg module¶
-
class
datad.maskedImg.
MaskedImg
(img, *, mask=None, masked_zero: bool = False, vmax: Optional[int] = None, vmin: Optional[int] = None)¶ Bases:
object
Image with binary mask.
- Parameters
img (str or image matrix) – Base image or its path.
mask (str or binary matrix) – Binary mask or its path.
masked_zero (bool, optional) – Whether the pixels with zero value in mask is masked. default False, the pixels with one value is masked.
vmax (int, optional) – Value maximum, useful in plotting.
vmin (int, optional) – Value minimum, useful in plotting.
-
coo_view
()¶ Return the coordinates view
- Returns
coordinates_value – Coordinates and values. N is the number of unmasked pixels First column is the y coordinates, second is the x coordinates and the last one is the intensity
- Return type
a N*3 ndarray
-
enumerate
()¶
-
flipX
() → datad.maskedImg.MaskedImg¶ Flip the image along x direction
-
flipY
() → datad.maskedImg.MaskedImg¶ Flip the image along y direction
-
property
masked_img
¶
-
rotate180
() → datad.maskedImg.MaskedImg¶ Rotate the image by 180 degrees
-
rotate270
() → datad.maskedImg.MaskedImg¶ Rotate the image by 270 degrees
-
rotate90
(k: int = 1) → datad.maskedImg.MaskedImg¶ Rotate the image by 90 degrees clockwise
- Parameters
k (int, optional) – the times of the rotation. default 1
-
show
(masked=True, *, ax=None, cmap: str = 'jet', limit: bool = True, **kwargs) → None¶ Plot the masked picture
- Parameters
masked (bool, optional) – Whether showing the masked image. if False, the image without mask will be shown defualt True
ax (optional) – Axes to be plotted at. If not specified, a new axes will be created.
cmap (str, optional) – Color map. default ‘jet’.
limit (bool, optional) – Whether applying the
vmax
andvmin
. default True.kwargs (map) – Remaining keyword arguments will be directly passed to the
ax.imshow()
.
-
datad.maskedImg.
load_img
(obj)¶ Load image using
fabio
-
datad.maskedImg.
maenumerate
(marr)¶
datad.nonidealPolyXtal module¶
-
class
datad.nonidealPolyXtal.
NonidealPolyXtal
(unitcell: Union[datad.unitcell.UnitCell, datad.singleXtal.SingleXtal], matrices: Iterable[numpy.ndarray], *, portions: Optional[Iterable[Union[int, float]]] = None)¶ Bases:
object
Non-ideal polycrystalline specimen.
- Parameters
unitcell (UnitCell or SingleXtal) – Unit cell of singleXtal or singleXtal.
matrices (an array-like of 3*3 matrix with N elements) – Tranformation matrices in reciprocal space for each grains.
portions (an array-like of number with N elements, optional) – Volume portions of corresponding grains. default the grains has the same volume portions
-
calc_rcp_space
(hklrange: Iterable[Union[int, float]] = (5, 5, 5), *, hkls: Optional[Union[datad.hkl.HKL, Iterable[datad.hkl.HKL]]] = None) → datad.nonidealPolyXtal.NonidealPolyXtal¶ Calculate the reciprocal space
- Parameters
hklrange (3-element array, optional) – Maximum of the Euler angles. The default range is (5, 5, 5).
hkls (
HKL
or an array ofHKL
, optional, keyword) – Miller index triplets to be calculated If this argument are specified, the argumenthklrange
will be ignored
-
static
from_axis_angles
(unitcell: Union[datad.unitcell.UnitCell, datad.singleXtal.SingleXtal], axes: Iterable[Union[int, float]], angles: Iterable[Union[int, float]], *, portions: Optional[Iterable[Union[int, float]]] = None, is_degree: bool = True) → datad.nonidealPolyXtal.NonidealPolyXtal¶ Return a NonidealPolyXtal in which the orientations of the grains is represented by given axes and angles
- Parameters
unitcell (UnitCell or SingleXtal) – Unit cell of or single crystasl.
axes (a N*3 matrix) – Rotation axes
angles (a N-element array of number) – Rotation angles
portions (an array-like of number with N elements, optional) – Volume portions of corresponding grains. default the grains has the same volume portions.
is_degree (bool, optional) – Whether the input angles are in degree or in radian. default True.
-
static
from_eulers
(unitcell: Union[datad.unitcell.UnitCell, datad.singleXtal.SingleXtal], angles: Iterable[Union[int, float]], seq: str = 'zxz', *, portions: Optional[Iterable[Union[int, float]]] = None, is_degree: bool = True, reversed: bool = False) → datad.nonidealPolyXtal.NonidealPolyXtal¶ Return a NonidealPolyXtal in which orientations of grains are described as the input Euler angle triplets.
- Parameters
unitcell (UnitCell or SingleXtal) – Unit cell or single crystal.
angles (a N*3 matrix) – Euler angle triplets.
seq (str, optional) – Sequence of the Euler angle triplets. default “zxz”.
portions (an N-element array-like of number, optional) – Volume portions of corresponding grains. default the grains has the same volume portions.
is_degree (bool, optional) – Whether the input angles are in degree or in radian. default True.
reversed (bool, optional) – Whether reversing the rotation. default False.
-
static
from_misorientation
(unitcell: Union[datad.unitcell.UnitCell, datad.singleXtal.SingleXtal], num_grains: int, misorientation: Union[int, float], *, portions: Optional[Iterable[Union[int, float]]] = None, is_degree: bool = True) → datad.nonidealPolyXtal.NonidealPolyXtal¶ Return a NonidealPolyXtal in which orientation is included in a misorientation
- Parameters
unitcell (UnitCell or SingleXtal) – Unit cell or single crystal.
num_grains (number) – Number of grains.
misorientation (number) – Misorientation angle.
portions (an array-like of number with N elements, optional) – Volume portions of corresponding grains. default the grains has the same volume portions.
is_degree (bool, optional) – Whether the input angles are in degree or in radian. default True.
-
static
from_odf
(unitcell: Union[datad.unitcell.UnitCell, datad.singleXtal.SingleXtal], filename: str, *, is_degree: bool = True, phi1_col: int = 0, Phi_col: int = 1, phi2_col: int = 2, intensity_col: int = 3, do_sample: bool = True, num_grains: Optional[int] = None, phi1_prec: Union[int, float] = 0, Phi_prec: Union[int, float] = 0, phi2_prec: Union[int, float] = 0, eulerFunc: Optional[function] = None, reverse: bool = False, **kwargs)¶ Return a NonidealPolyXtal in which orientations of grains are based on given odf.
We implement two mode here: direct mode and sampling mode. In direct mode, we use the orientations and intensities directly given in the odf to construct the MonoSinglextals and the number of grains equals to the number of entries in odf. In sampling mode, we generate grains with a given number and the orientations of grains obeys given odf.
- Parameters
unitcell (UnitCell or SingleXtal) – Unit cell or single crystal.
filename (str) – File containing the discrete ODF.
phi1_col (number, optional) – Column number of the Euler angles of the ODF in the file. Column number starts with 0. The default column numbers is 0, 1, 2 and 3, respectively.
Phi_col (number, optional) – Column number of the Euler angles of the ODF in the file. Column number starts with 0. The default column numbers is 0, 1, 2 and 3, respectively.
phi2_col (number, optional) – Column number of the Euler angles of the ODF in the file. Column number starts with 0. The default column numbers is 0, 1, 2 and 3, respectively.
intensity_col (number optional) – Column number of the intensity of the ODF in the file. default the 3rd column
do_sample (bool, optional) – If True, the sampling mode will be applied. Otherwise the direct mode are applied. Defaults to be True.
num_grains (number) – Number of grains.
phi1_prec (number, optional) – Maximum of the noise added onto the sampled Euler angles. The default maximums are 5 degree for all angles.
Phi_prec (number, optional) – Maximum of the noise added onto the sampled Euler angles. The default maximums are 5 degree for all angles.
phi2_prec (number, optional) – Maximum of the noise added onto the sampled Euler angles. The default maximums are 5 degree for all angles.
Function (eulerFunc:) – Function to modify the input Euler angles
optional – Function to modify the input Euler angles
reverse (bool, optional) – Whether reversing the rotation
is_degree (bool, optional) – Whether the input angles are in degree or in radian the default number is True.
-
linear_transformation
(m: numpy.ndarray) → datad.nonidealPolyXtal.NonidealPolyXtal¶ Apply linear transformation to this single crystal
- Parameters
m (3*3 Matrix) – Transformation matrix.
- Returns
nonidealPolyXtal – transformed non-ideal polycrystalline specimen
- Return type
-
mirror
(normal: Iterable[Union[int, float]]) → datad.nonidealPolyXtal.NonidealPolyXtal¶ Mirror non-ideal polycrystalline specimen.
- Parameters
normal (3-element array of number.) – Normal direction of mirror plane.
- Returns
transformed non-ideal polycrystalline specimen
- Return type
nonidealPolyXtal
-
rotate_by_axis_angle
(axis: Iterable[Union[int, float]], angle: float, *, is_degree: bool = True) → datad.nonidealPolyXtal.NonidealPolyXtal¶ Rotate the nonideal polycrystalline specimen with axis-angle notation.
- Parameters
axis (3-element array of float) – Rotation axis.
angle (float) – Rotation angle.
is_degree (bool, optional) – Whether the input angle is in degree. The default value is True.
- Returns
nonidealPolyXtal – transformed non-ideal polycrystalline specimen
- Return type
-
rotate_by_eulers
(angles: Iterable[Union[int, float]], seq: str = 'zxz', *, is_degree: bool = True) → datad.nonidealPolyXtal.NonidealPolyXtal¶ Rotate the nonideal polycrystalline specimen with Euler angle triplets notation.
- Parameters
angles (3-element vector) – Euler angle triplets.
seq (str, optional) – Sequence of rotation axis. The letters must belong to the set {‘x’, ‘y’, ‘z’} default ‘zxz’
is_degree (bool, optional) – Whether the input angles are in degrees. default True.
- Returns
nonidealPolyXtal – transformed non-ideal polycrystalline specimen
- Return type
-
save_rcp_space
(filename: str)¶ Save the reciprocal space to file.
- The format like this:
10 # number of data rows # h k l kx ky kz intensity(real) intensity(imag) 1 1 0 1 1 0 100 100 ……
If reciprocal space is not calculated, a ValueError will be raised.
- Parameters
filename (str) – Path of file.
-
strain
(e11: Union[int, float], e22: Union[int, float], e33: Union[int, float], e12: Union[int, float], e13: Union[int, float], e23: Union[int, float]) → datad.nonidealPolyXtal.NonidealPolyXtal¶ Apply strain to the single crytal.
-
strain1d
(ratio: float, *, axis: Iterable[Union[int, float]] = None, hkl: datad.hkl.HKL = None) → datad.nonidealPolyXtal.NonidealPolyXtal¶ Apply a 1D strain to non-ideal polycrystalline specimen.
- Parameters
ratio (float) – Strain ratio.
axis (vector, exclusive with
hkl
) – Direction of strain in sample coordinate system.hkl (HKL, exclusive with
axis
) – Miller index triplets of the direction of strain.
- Returns
nonidealPolyXtal – transformed non-ideal polycrystalline specimen.
- Return type
-
static
uniform
(lattice: Union[datad.unitcell.UnitCell, datad.singleXtal.SingleXtal], n: int) → datad.nonidealPolyXtal.NonidealPolyXtal¶ Return a NonidealPolyXtal which have random orientations and no strain.
- Parameters
unitcell (UnitCell or SingleXtal) – Unit cell or single crystal.
n (int) – Number of grains.
-
vecs_in_rcp
(hkls: Union[datad.hkl.HKL, Iterable[datad.hkl.HKL]], *, convert_to_unit: bool = False) → numpy.ndarray¶ Returns the reciprocal vectors of given miller index triplets in sample coordinates system.
- Parameters
hkls (HKL or an array-like of HKL) – Miller index triplets
convert_to_unit (bool, optional) – If True, the output vectors are all converted to unit vectors.
- Returns
vectors – reciprocal vectors.
- Return type
array
datad.polyXtal module¶
-
class
datad.polyXtal.
PolyXtal
(unitcell: datad.unitcell.UnitCell, *, name: Optional[str] = None)¶ Bases:
object
Ideal polycrystal
- Parameters
unitcell (UnitCell) – Unit cell
name (str, optional) – Name of polyXtal
-
calc_rcp_space
(hklrange: Iterable[Union[int, float]] = (5, 5, 5), *, hkls: Optional[Union[datad.hkl.HKL, Iterable[datad.hkl.HKL]]] = None) → datad.polyXtal.PolyXtal¶ Calculate the reciprocal space.
For ideal polycrystalline specimen, its reciprocal space consists of the Polanyi spheres. Only the radii of these spheres is stored.
The hkls will be grouped by the corresponding d-spacing and we pick representative ones from the hkls with same d-spacing to be stored. As consequence, the number of hkls stored equals to the number of spheres in reciprocal space.
- Parameters
hklrange (vector, exclusive with
hkls
) – Maximum of Miller index triplets. The default maximum is (5,5,5).hkls (vector or vectors, exclusive with
hklrange
) – Miller index triplets to be calculated. Note that input hkls is considered as Miller indices of crystal planes rather than the representative miller indices of a family of crystal planes.
- Returns
polycrystal
- Return type
-
create_hkls
(hklrange: Iterable[Union[int, float]] = (5, 5, 5), *, extinct: bool = True) → numpy.ndarray¶ Create Miller index triplets within given range.
Equivalence of HKL is not considered here, such as the Miller index triplets with same d-spacing,
- Parameters
hklrange (vector, optional) – Maximum range of miller index triplets. the default maximum is (5,5,5).
extinct (bool, optional) – If True, extinct Miller index triplets in this unit cell will be excluded.
- Returns
hkls – Generated Miller index triplets.
- Return type
an array of HKL
-
d_spacing
(hkls: Union[datad.hkl.HKL, Iterable[datad.hkl.HKL]]) → numpy.ndarray¶ Interplanar or d_spacing of given hkls
- Parameters
hkls (HKL or an array-like of HKL) – Miller index triplets.
- Returns
d_spacing
- Return type
array of float
-
save_rcp_space
(filename: str)¶ Save reciprocal space to file
- the file format is like this:
10 # number of data rows # h k l radius intensity 1 0 0 0.1 1e7 ……
- Parameters
filename (str) – Path of file.
-
class
datad.polyXtal.
PolyXtals
(polyXtals: Union[datad.polyXtal.PolyXtal, Iterable[datad.polyXtal.PolyXtal]], *, portions: Optional[Iterable[Union[int, float]]] = None)¶ Bases:
object
Collection of PolyXtal.
- Parameters
polyXtals (PolyXtal or an array-like of PolyXtal) – List of
PolyXtal
.portions (vector, optional) – Volume proportions of polyXtal. The shape of
portions
must match the shape ofpolyXtals
.
-
calc_rcp_space
(hklrange: Iterable[Union[int, float]] = (5, 5, 5), *, hkls: Optional[Union[datad.hkl.HKL, Iterable[datad.hkl.HKL]]] = None) → None¶ Calculate the reciprocal space
The reciprocal space of the polyXtal element in this
PolyXtals
will not be re-calculated if the reciprocal space have been calculated.Portions are considered here.
- Parameters
hklrange (vector, exclusive with
hkls
) – Maximum of Miller index triplets. The default maxium is (5,5,5).hkls (vector or vectors, exclusive with
hklrange
) – Miller index triplets to be calculated. Note that input hkls is considered as Miller indices of crystal planes rather than the representative miller indices of a family of crystal planes.
-
property
portions
¶
-
to_list
() → List[datad.polyXtal.PolyXtal]¶ Returns the list of PolyXtal
datad.rotation module¶
-
datad.rotation.
apply_linear_transform
(vs: Union[Iterable[Union[int, float]], Iterable[Iterable[Union[int, float]]]], m: numpy.ndarray, *, out=None) → Union[Iterable[Union[int, float]], Iterable[Iterable[Union[int, float]]]]¶ Apply linear transform to vectors. Linear transform includes rotation, mirroring, scaling, shearing and so on.
- Parameters
vs (vectors) – Vectors to be tranformed
m (3*3 Matrix) – Transformation matrix.
out (vectors, optional) – If specified, the results will be output to this vectors.
- Returns
vs – transformed vectors
- Return type
vectors
-
datad.rotation.
mirror_matrix
(normal: Iterable[Union[int, float]]) → numpy.ndarray¶ Returns the mirroring matrix
- Parameters
normal (3-element array of float) – normal direction of mirror plane
-
datad.rotation.
random_rotation_matrix
(N: Optional[int] = None) → numpy.ndarray¶ Draw a random rotation matrix from the uniform random rotation matrices. Here, unit quaternion is used for random uniformly
-
datad.rotation.
random_rotation_matrix_in_range
(N: Optional[int] = None, max_angle: Union[int, float] = inf, *, is_degree: bool = True) → numpy.ndarray¶
-
datad.rotation.
random_rotation_matrix_in_range_by_euler
(N: Optional[int] = None, max_angle: Union[int, float] = inf, *, is_degree: bool = True) → numpy.ndarray¶
-
datad.rotation.
random_uniform_unit
(*shape: Iterable[Union[int, float]]) → Union[Iterable[Union[int, float]], Iterable[Iterable[Union[int, float]]]]¶ Random unit vectors which is distributed uniformly on a sphere.
Ones always random three uniform numbers in range [0,1] and normalize them to get the expected vectors, but the method is proved to be wrong.
Here we random three numbers in standard normal distribution and normalize them to be a unit vector, which is proved uniform on the sphere.
See [here](https://www.zhihu.com/question/26579222) for details.
-
datad.rotation.
rotate_by_axis_angle
(vs: Union[Iterable[Union[int, float]], Iterable[Iterable[Union[int, float]]]], axis: Iterable[Union[int, float]], angle: float, *, is_degree: bool = False, out=None) → Union[Iterable[Union[int, float]], Iterable[Iterable[Union[int, float]]]]¶ Rotate vectors by axis-angle notation.
- Parameters
vs (vectors) – Vectors to be rotated
axis (3-element array of float) – Rotation axis
angle (float) – Rotation angle
is_degreee (bool, optional) – whether the input angles are in degrees. The default value is False.
out (vectors, optional) – the destination the result output to default allocate new vectors
- Returns
rotated_vs – rotated vectors
- Return type
vectors
-
datad.rotation.
rotate_by_eulers
(vs: Union[Iterable[Union[int, float]], Iterable[Iterable[Union[int, float]]]], angles: Iterable[Union[int, float]], seq: str = 'zxz', *, is_degree: bool = False, out=None) → Union[Iterable[Union[int, float]], Iterable[Iterable[Union[int, float]]]]¶ Rotate vectors by Euler angle triplets notation.
- Parameters
vs (vectors) – Vectors to be rotated.
angles (3-element array-like of float) – Euler angle triplets.
seq (str, optional) – Sequence of rotation axis. The letters must belong to the set {‘x’, ‘y’, ‘z’}. default ‘zxz’.
is_degree (bool, optional) – Whether the input angles are in degrees. The default value is False.
out (vectors, optional) – If specified, the results will be output to this vectors.
- Returns
rotated_vs – rotated vectors
- Return type
vectors
-
datad.rotation.
rotation_matrix_from_axis_angle
(axis: Iterable[Iterable[Union[int, float]]], angle: Iterable[Union[int, float]], *, is_degree: bool = False) → numpy.ndarray¶ Obtain rotation matrices from axes and angles.
- Parameters
axis (N*3 array of float) – Rotation axis
angle (N array of float) – Rotation angle
is_degree (bool, optional) – Whether the input angle are in degrees. The default value is True.
- Returns
rotation_matrix – Rotation matrix
- Return type
N*3*3 Matrix
-
datad.rotation.
rotation_matrix_from_eulers
(angles: Iterable[Union[int, float]], seq: str = 'zxz', *, is_degree: bool = False, reversed: bool = False) → numpy.ndarray¶ Obtain rotation matrix from euler angles.
- Parameters
angles (N*3 array-like of float) – Euler angles
seq (str, optional) – Sequence of rotation axis. The letters must belong to the set {‘x’, ‘y’, ‘z’} default ‘zxz’.
is_degree (bool, optional) – Whether the input angles are in degrees. The default value is False.
reverse (bool, optional) – If True, the rotation will be reversed.
- Returns
rotation_matrix – rotation matrix
- Return type
N*3*3 Matrix
datad.simu1d module¶
-
class
datad.simu1d.
Curve1D
(polyXtals: Union[datad.polyXtal.PolyXtal, Iterable[datad.polyXtal.PolyXtal]], xray: datad.xray.Xray)¶ Bases:
object
1D diffration curve.
- Parameters
-
calc_1d_intensity
(min_tth: Optional[Union[int, float]] = None, max_tth: Optional[Union[int, float]] = None, *, peak_width: Union[int, float] = 0.1, resolution: Union[int, float] = 0.001, is_degree: bool = True) → None¶ Calculate the 1D diffraction curve.
Gaussian shapes are applied to the diffraction peaks.
- Parameters
min_tth (number, optional) – Minimum of the range of scattering angle 2θ.
max_2th (number, optional) – Maximum of the range of scattering angle 2θ.
peak_width (number, optional) – Sigma (standard deviation) of the Gaussian peaks. The default sigma is 0.1 degree.
resolution (number, optional) – Sigma (standard deviation) of the Gaussian peaks. The default sigma is 0.1 degree.
is_degree (bool, optional) – whether the input angles are in degrees. The default value is True.
-
calc_peaks
(min_tth: Union[int, float] = 0, max_tth: Union[int, float] = 180, *, is_degree: bool = True, sort_by: Optional[datad.simu1d.SortKey] = None)¶ Calculate the 1D diffraction peaks.
- Parameters
min_tth (number) – Min scattering angle of the diffraction peaks. This parameter will be checked to be greater than 0 degree and less than 180 degree. The default value is 0 degree.
max_tth (number) – Max scattering angle of the diffraction peaks. This parameter will be checked to be greater than 0 degree and less than 180 degree. The default value is 90 degree.
is_degree (bool, optional) – Whether the input angles are in degrees. The default value is True.
sort_by (str, optional) – Sort the diffraction peaks by given key. Available options are
"tth"
,"intensity"
and"wavelength"
. The default order of diffraction peaks follows the input order of the polycrystalline specimens first, and then the order of the reciprocal vectors in the specimen.
-
peak_angles
(*, is_degree: bool = True) → Iterable[float]¶ Return the scattering angles of peaks, aka 2heta if reciprocal space is not calculated, an empty list will be returned
- Parameters
is_degree (bool, optional) – Whether the output angles are in degrees. The default value is True.
- Returns
angles – Scattering angles.
- Return type
an array of float
-
peak_d_spacings
() → Iterable[float]¶ Return the associated d_spacing of peaks
-
peak_grains
() → Iterable[datad.polyXtal.PolyXtal]¶ Return the polycrystalline specimens which peaks belong to
-
peak_hkls
() → Iterable[datad.hkl.HKL]¶ Return Miller index triplets of peaks
-
peak_intensities
() → Iterable[float]¶ Returns the intensities of peaks
-
peak_num
() → int¶ Return the number of peaks
-
peak_wavelength
() → Iterable[float]¶ Return the associated wavelengths of peaks
-
property
polyXtals
¶
-
save
(path: str) → None¶ Save the diffraction peaks to file.
Format of file follows:
13 # number of data rows # h k l grain 2theta intensity d_spacing wavelength r_intensity 1 0 0 Ta 20.0 4e5 0.2 1 100 ......
- Parameters
path (str) – path of file.
-
show
(peak_width: Union[int, float] = 0.1, resolution: Union[int, float] = 0.001, *, show_tagged: bool = True, show_label: bool = True, save_fig: Optional[str] = None) → None¶ Plot the 1D intensity curve.
- Parameters
peak_width (number) – Sigma (standard deviation) of the Gaussian peaks. The default sigma is 0.1 degree.
resolution (number) – Sigma (standard deviation) of the Gaussian peaks. The default sigma is 0.1 degree.
show_tagged (bool, optional) – Whether emphasising peaks with tagged associated wavelengths. The default value is True.
show_label (bool) – Whether plotting the labels of peaks. The default value is True.
save_fig (str, optional) – If specified, the figure will be saved to file at specific path.
-
property
xray
¶
datad.simu2d module¶
-
class
datad.simu2d.
Pattern2D
(singleXtals: Union[datad.singleXtal.SingleXtal, Iterable[datad.singleXtal.SingleXtal], datad.nonidealPolyXtal.NonidealPolyXtal], xray: datad.xray.Xray, *, inc: Iterable[Union[int, float]] = (0, 0, - 1), vx: Iterable[Union[int, float]] = (1, 0, 0))¶ Bases:
object
2d diffraction pattern
- Parameters
singleXtals (SingleXtal or an array-like of SingleXtals or NonidealPolyXtal) – Single crystal(s) or non-ideal polycrystalline specimen.
xray (Xray) – X-ray spectrum.
inc (vector, optional) – Incident direction of xray. The default incident direction is the -z-axis of the sample coordinate system.
vx (vector, optional) – Transverse direction which azimuthal angle is zero. The orthorgonality of
inc
andvx
will be checked. The default transverse direction is the x-axis of the sample coordinate system.
-
binning_along_gamma
(min_gamma: Union[int, float] = 0, max_gamma: Union[int, float] = 360, num_gamma: int = 360, *, is_degree: bool = True, average: bool = False)¶ Bin the intensities along azimuthal angle γ.
-
binning_along_tth
(min_tth: Union[int, float] = 0, max_tth: Union[int, float] = 180, num_tth: int = 180, *, is_degree: bool = True, average: bool = False)¶ Bin the intensities along scattering angles 2θ.
-
calc_peaks
(min_tth: Union[int, float] = 0, max_tth: Union[int, float] = 180, min_gamma: Union[int, float] = 0, max_gamma: Union[int, float] = 360, *, is_degree: bool = True, sort_by: Optional[datad.simu1d.SortKey] = None)¶ Calculate the 2D diffraction peaks. The position of 2D diffraction peaks are represented by scattering angles 2θ and azimuthal angles γ.
- Parameters
min_tth (number, optional) – Minimum of scattering angle 2θ This parameter will be checked to be greater than 0 degree and less than 180 degree. The default value is 0 degree.
max_2th (number, optional) – Maximum of scattering angle 2θ This parameter will be checked to be greater than 0 degree and less than 180 degree. The default value is 180 degree.
min_gamma (number, optional) – Minimum of azimuthal angle γ. This parameter will be checked to be greater then -360 degree and less than 360 degree The default value is 0 degree.
max_gamma (number) – Maximum of azimuthal angle γ. This parameter will be checked to be greater then -360 degree and less than 360 degree The default value is 360 degree.
is_degree (bool, optional) – Whether the input angles are in degrees. The default value is True.
sort_by (str, optional) – If specified, sort the diffraction peaks by given key. Available options are
"tth"
,"gamma"
,"intensity"
and"wavelength"
. The default order of diffraction peaks follows the input order of the single crystal specimens first, and then the order of the reciprocal vectors in the specimen.
-
property
inc
¶
-
peak_d_spacings
() → Iterable[float]¶ Returns the interplanar or d_spacing of each peak.
-
peak_gammas
(*, is_degree: bool = True) → Iterable[float]¶ Return the azimuthal angle of each peak, aka γ
- Parameters
is_degree (bool, optional) – Whether the output angles are in degrees. The default value is True.
- Returns
angles – azimuthal angles
- Return type
a numpy array of float
-
peak_grains
() → Iterable¶ Returns the name of grain which each peak belongs to.
-
peak_hkls
() → Iterable[datad.hkl.HKL]¶ Returns the Miller index triplet of each peak.
-
peak_intensities
() → Iterable[float]¶ Return the intensity of each peak.
-
peak_num
() → int¶ Returns the number of peaks.
-
peak_rcp_vecs
() → Iterable[Iterable[Union[int, float]]]¶ Return the corresponding reciprocal vector of each peak.
-
peak_tths
(*, is_degree: bool = True) → Iterable[float]¶ Returns scattering angles of peaks, aka 2θ.
- Parameters
is_degree (bool, optional) – Whether the output angles are in degrees. The default value is True.
- Returns
angles – scattering angles
- Return type
an array of float
-
peak_vecs_out
() → Iterable[Iterable[Union[int, float]]]¶ Return the corresponding scattered vector of each peak.
-
peak_wavelength_intensities
() → Iterable[float]¶ Return the intensity of the associated wavelength of each peak.
-
peak_wavelengthes
() → Iterable[float]¶ Return the associated wavelengths of each peak.
-
save
(path: str) → None¶ Save the diffraction peaks to file.
Format of file follows:
13 # number of data rows # h k l grain 2theta gamma kx ky kz d_spacing intensity wavelength 1 0 0 Ta 20. 0. 0.5 0 0 4e5 1 ......
- Parameters
path (str) – path to file.
-
save_binning_gamma
(path: str)¶ Save the result of binning along γ to file.
-
save_binning_tth
(path: str)¶ Save the result of binning along 2θ to file.
-
set_inc
(inc: Iterable[Union[int, float]]) → None¶ Set the incident direction of X-ray.
-
set_vx
(vx: Iterable[Union[int, float]]) → None¶ Set the transverse direction of X-ray.
-
show
(max_tth: Optional[Union[int, float]] = None, *, is_degree: bool = True, log: bool = False, small: bool = True) → None¶ Plot to show the 2D diffraction pattern.
- Parameters
max_tth (number, optional) – Maximum of the scattering angles 2θ.
is_degree (bool, optional) – whether the input angles are in degrees. The default value is True.
log (bool, optional) – If True, the color map will be based on the logarithm of intensities rather than the intensities themselves.
small (bool, optional) – If True, the marker size of the plotted diffraction spots will be small one. The default value is True.
-
show_binning_gamma
(**kwargs)¶ Plot to show the results of binning along γ.
-
show_binning_tth
(**kwargs)¶ Plot to show the results of binning along 2θ.
-
property
singleXtals
¶
-
property
vx
¶
-
property
xray
¶
datad.singleXtal module¶
-
class
datad.singleXtal.
SingleXtal
(unitcell: datad.unitcell.UnitCell, orientation_matrix: numpy.ndarray, *, name: str = '')¶ Bases:
object
Single Crystal.
The difference between SingleXtal and UnitCell is that the orientation of SingleXtal in sample coordinates system must be specified.
The key conception in SingleXtal is the reciprocal matrix in sample coordinates system. It consists of three basic vectors of reciprocal space in sample coordinates system. It can be obtained by the vectors in lattice orthogonal coordinates system and the orientation matrix (rotation matrix) of lattice orthogonal coordinates system related to sample one. First one is obtained from associate Lattice and the second one can be calculated by many methods.
Orientation matrix R is an orthogonal matrix relating lattice orthogonal coordinates system and sample coordinates system. The reciprocal matrix in sample coordinates system M∗ is calculated as M∗=M∗LRT. where, M∗L is the reciprocal matrix in lattice orthognal coordinates system and subscript T means transpose of matrix.
- Parameters
unitcell (UnitCell) – the unit cell of the lattice forming this single crystal
orientation_matrix (a 3*3 matrix) – orientation matrix R
name (str, optional) – the name of this SingleXtal
-
calc_rcp_space
(hklrange: Iterable[Union[int, float]] = (5, 5, 5), *, hkls: Optional[Union[datad.hkl.HKL, Iterable[datad.hkl.HKL]]] = None) → datad.singleXtal.SingleXtal¶ Calculate the reciprocal vectors of this single crystal.
- Parameters
hklrange (vector, optional, exclusive with
hkls
) – Maximum of Miller index triplet. The default maximum is (5,5,5).hkls (hkl or an array of hkl, exclusive with
hklrange
) – the array of Miller index triplets to be calculated.
- Returns
single_crystal – the original single crystal with calculated reciprocal space
- Return type
-
copy
() → datad.singleXtal.SingleXtal¶ Return a deep copy of this
SingleXtal
-
property
direct_matrix
¶ Direct matrix in sample coordinate system
-
static
from_miller_indices
(unitcell: datad.unitcell.UnitCell, *, x: Optional[datad.hkl.HKL] = None, y: Optional[datad.hkl.HKL] = None, z: Optional[datad.hkl.HKL] = None, name: Optional[str] = '') → datad.singleXtal.SingleXtal¶ Initialize a
SingleXtal
by the Miller index triplets along the x-, y- or z-axis of sample coordinates system.- Parameters
unitcell (UnitCell) – Unit cell.
x (HKL) – Miller index triplet of lattice along the x-axis of sample coordinate system.
y (HKL) – Miller index triplet of lattice along the y-axis of sample coordinate system.
z (HKL) – Miller index triplet of lattice along the z-axis of sample coordinate system.
name (str, optional) – the name of this SingleXtal default “”
- Returns
single_crystal – single crystal
- Return type
See also
-
static
from_rcp_vectors
(unitcell: datad.unitcell.UnitCell, *, x: Optional[Iterable[Union[int, float]]] = None, y: Optional[Iterable[Union[int, float]]] = None, z: Optional[Iterable[Union[int, float]]] = None, name: Optional[str] = '') → datad.singleXtal.SingleXtal¶ Intialize a
SingleXtal
by the unitcell and the reciprocal vectors in lattice orthogonal coordinate system along the x-, y- or z-axis of sample coordinates system.At least two of these three vectors should be specified, otherwise a ValueError will be raised.
The orthogonality of these three vectors will be also checked.
- Parameters
unitcell (UnitCell) – Unit cell.
x (vector) – Reciprocal vectors in lattice orthogonal coordinates system along the x-axis of sample coordinates system.
y (vector) – Reciprocal vectors in lattice orthogonal coordinates system along the y-axis of sample coordinates system.
z (vector) – Reciprocal vectors in lattice orthogonal coordinates system along the z-axis of sample coordinates system.
name (str, optional) – the name of this
SingleXtal
.
- Returns
single_crystal – single crystal
- Return type
-
linear_transformation
(m: numpy.ndarray) → datad.singleXtal.SingleXtal¶ Apply linear transformation to this single crystal.
- Parameters
m (3*3 Matrix) – Transformation matrix.
- Returns
single_xtal – transformed single crystals
- Return type
-
mirror
(normal: Iterable[Union[int, float]]) → datad.singleXtal.SingleXtal¶ Mirror the single crystal.
- Parameters
normal (3-element array of number.) – Normal direction of mirror plane.
- Returns
single_crystal – transformed single crystal.
- Return type
-
static
random
(unitcell: datad.unitcell.UnitCell, *, name: str = '') → datad.singleXtal.SingleXtal¶ Returns a
SingleXtal
with random orientation.- Parameters
unitcell (UnitCell) – unit cell.
name (str, optional) – the name of this
SingleXtal
. default “”.
- Returns
single_xtal – single xtal with random orientation
- Return type
-
property
rcp_matrix
¶ Reciprocal matrix in sample coordinates system
-
rotate_by_axis_angle
(axis: Iterable[Union[int, float]], angle: float, *, is_degree: bool = True) → datad.singleXtal.SingleXtal¶ Rotate the single crystal with axis-angle notation
- Parameters
axis (3-element array of float) – Rotation axis.
angle (float) – Rotation angle.
is_degree (bool, optional) – Whether the input angle is in degree. The default value is True.
- Returns
single_xtal – transformed single crystal
- Return type
-
rotate_by_eulers
(angles: Iterable[Union[int, float]], seq: str = 'zxz', *, is_degree: bool = True) → datad.singleXtal.SingleXtal¶ Rotate the single crystal with euler angle triplets notation.
- Parameters
angles (3-element vector) – Euler angle triples
seq (str, optional) – Sequence of rotation axis. The letters must belong to the set {‘x’, ‘y’, ‘z’} default ‘zxz’
is_degree (bool, optional) – Whether the input angles are in degrees. default True.
- Returns
single_crystal – tranformed single crystal
- Return type
SingelXtal
-
save_rcp_space
(path: str)¶ Save the reciprocal vectors to file.
The format like this:
10 # number of data rows # h k l kx ky kz intensity(real) intensity(imag) 1 1 0 1 1 0 100 100 ......
If reciprocal space is not calculated, a ValueError will be raised.
- Parameters
path (str) – path of file.
-
save_rcp_space_for_dct
(path: str)¶ Save the reciprocal vectors to file for dct calculation.
The format like this:
0.000000 0.000000 0.494315 1157.737713 0.000000 0.000000 -0.494315 1157.737713
Four columns correspond to x-, y-, z-coordinates and the associated modulus of intensity, respectively.
If reciprocal space is not calculated, a ValueError will be raised.
- Parameters
path (str) – path of file.
-
set_rcp_matrix
(m: numpy.ndarray)¶ Set a user-defined reciprocal matrix.
-
strain
(e11: Union[int, float], e22: Union[int, float], e33: Union[int, float], e12: Union[int, float], e13: Union[int, float], e23: Union[int, float]) → datad.singleXtal.SingleXtal¶ Apply strain to the single crytal.
-
strain1d
(ratio: float, *, axis: Iterable[Union[int, float]] = None, hkl: datad.hkl.HKL = None) → datad.singleXtal.SingleXtal¶ Apply a 1D strain to this single crystal
- Parameters
ratio (float) – Strain ratio.
axis (vector, exclusive with
hkl
) – Direction of strain in sample coordinate system.hkl (HKL, exclusive with
axis
) – Miller index triplets of the direction of strain.
- Returns
single_crystal – transformed single crystal.
- Return type
-
vecs_in_direct
(uvws: Union[datad.hkl.UVW, Iterable[datad.hkl.UVW]], *, convert_to_unit: bool = False) → numpy.ndarray¶ reciprocal vectors of given lattice direction index triplets in sample coordinates system.
- Parameters
uvws (UVW or an array-like of UVW) – Lattice direction index triplet(s).
convert_to_unit (bool, optional) – If True, the output direct vectors will be normalized and corresponding unit vectors will be returned.
- Returns
vectors – direct vectors
- Return type
vector(s)
-
vecs_in_rcp
(hkls: Union[datad.hkl.HKL, Iterable[datad.hkl.HKL]], *, convert_to_unit: bool = False) → numpy.ndarray¶ Return the reciprocal vectors of given Miller index triplets in sample coordinate system.
- Parameters
hkls (HKL or an array-like of HKL) – Miller index triplets
convert_to_unit (bool, optional) – If True, the output reciprocal vectors will be normalized and corresponding unit vectors will be returned.
- Returns
vectors – reciprocal vectors
- Return type
vector(s)
datad.singleXtals module¶
-
class
datad.singleXtals.
SingleXtals
(singleXtals: Union[datad.singleXtal.SingleXtal, Iterable[datad.singleXtal.SingleXtal]], *, portions: Optional[Iterable[Union[int, float]]] = None)¶ Bases:
object
Collection of
SingleXtal
.- Parameters
singleXtals (SingleXtal or an array-like of SingleXtal) – One singlecrystal specimen or a list of singlecrystal specimens.
portions (vector of float, optional) – Volume portions of the singlecrystal specimens. The shape of
portions
must match the shape ofsingleXtals
-
calc_rcp_space
(hklrange: Iterable[Union[int, float]] = (5, 5, 5), *, hkls: Optional[Union[datad.hkl.HKL, Iterable[datad.hkl.HKL]]] = None) → None¶ calculate the reciprocal vectors.
Reciprocal vectors of each
SingleXtal
in thisSingleXtals
will not be re-calculated if its reciprocal vectors have been calculated.Volume portions are considered here and influence the intensities of reciprocal vectors.
- Parameters
hklrange (vector, exclusive with
hkls
) – Maximum of Miller index triplets. The default maximum is (5,5,5).hkls (HKL or an array-like of HKL, exclusive with
hklrange
) – Miller index triplets to be calculated.
-
linear_transformation
(m: numpy.ndarray, *, recuisive: bool = True, simple: bool = False) → datad.singleXtals.SingleXtals¶ Apply linear transformation.
- Parameters
m (Matrix) – Transformation matrix T.
recuisive (bool, optional) – If True, the transformation will be applied to all the sub
SingleXtal``s itself. Otherwise, the transformation only is applied to the reciprocal space in this group of ``SingleXtal
, which is faster and useful when you will never access the sub singleXtals. The default value is True.simple (bool, optional) – If True and the reciprocal space of SingleXtals has been calculated, the new reciprocal space after transformation will not be collected from the sub SingleXtal and directly transform the current reciprocal space. If all SingleXtal have the same lattice, this result will be correct and faster than collecting. If there are many lattice in SingleXtals, an Error will be raised. The default value is False.
- Returns
single_crystals
- Return type
-
mirror
(normal: Iterable[Union[int, float]], *, recuisive: bool = True, simple: bool = False) → datad.singleXtal.SingleXtal¶ Mirror the
SingleXtals
.- Parameters
normal (3-element array of number.) – Normal direction of mirror plane.
- Returns
single_crystal
- Return type
-
property
portions
¶
-
static
random
(unitcell: datad.unitcell.UnitCell, num_grains: Union[int, float] = 1000) → datad.singleXtals.SingleXtals¶ Generate a
SingleXtals
in which grains have random orientations.- Parameters
unitcell (UnitCell) – unit cell.
num_grains (number) – Number of grains in the
SingleXtals
. The default value is 1000.
-
rotate_by_axis_angle
(axis: Iterable[Union[int, float]], angle: float, *, is_degree: bool = True, recuisive: bool = True, simple: bool = False) → datad.singleXtals.SingleXtals¶ Rotate with axis-angle notation.
- Parameters
axis (3-element array of float) – Rotation axis.
angle (float) – Rotation angle.
is_degree (bool, optional) – Whether the input angle is in degree. The default value is True.
- Returns
single_crystals
- Return type
-
rotate_by_eulers
(angles: Iterable[Union[int, float]], seq: str = 'zxz', *, is_degree: bool = True, recuisive: bool = True, simple: bool = False) → datad.singleXtal.SingleXtal¶ Rotate with Euler angle triplets notation.
- Parameters
angles (3-element vector) – Euler angle triplets.
seq (str, optional) – Sequence of rotation axis. The letters must belong to the set {‘x’, ‘y’, ‘z’} default ‘zxz’
is_degree (bool, optional) – Whether the input angles are in degrees. default True.
- Returns
single_crystal – single crystal
- Return type
SingelXtal
-
strain
(e11: Union[int, float], e22: Union[int, float], e33: Union[int, float], e12: Union[int, float], e13: Union[int, float], e23: Union[int, float]) → datad.singleXtals.SingleXtals¶ Apply strain.
-
strain1d
(ratio: float, *, axis: Iterable[Union[int, float]] = None, hkl: datad.hkl.HKL = None, recuisive: bool = True, simple: bool = False) → datad.singleXtals.SingleXtals¶ Apply a 1D strain.
- Parameters
ratio (float) – Strain ratio.
axis (vector, exclusive with
hkl
) – Direction of strain in sample coordinate system.hkl (HKL, exclusive with
axis
) – Miller index triplets of the direction of strain.
- Returns
single_crystal
- Return type
-
to_list
() → List[datad.singleXtal.SingleXtal]¶ Return the list of
SingleXtal
datad.unitcell module¶
-
class
datad.unitcell.
UnitCell
(latticeparameter: datad.latticeparameters.LatticeParameters, atoms: datad.atom.AtomsInCell)¶ Bases:
object
Unit cell.
Lattice consists of lattice parameters and atoms with their fractional coordinates in the unit cell.
-
property
atoms
¶ Atoms with their fractional coordinate in the unit cell.
-
create_hkls
(hklrange: Iterable[Union[int, float]] = (5, 5, 5), *, extinct: bool = True, include_negative: bool = True) → numpy.ndarray¶ Create a group of Miller index triplets within given range. Extinct hkls will be omited here.
- Parameters
hklrange (3-element array-like of int) – Maximum of miller index triplets. The default maximum is (5,5,5).
extinct (bool, optional) – If True, extinct Miller index triplets in this unitcell will be excluded. The default value is True.
include_negative (bool, optional) – If True, the generated Miller index triplets will include negative indices. The default value is True.
- Returns
hkls
- Return type
an array of HKL
-
d_spacing
(hkls: Union[datad.hkl.HKL, Iterable[datad.hkl.HKL]]) → numpy.ndarray¶ Calculate the interplanar or d-spacing.
- Parameters
hkls (HKL or an array of HKL) – Miller index triplet(s).
- Returns
d_spacing
- Return type
an array of float
-
static
from_array
(lpArray: Iterable[Union[int, float]], atomsArray: Iterable[Tuple[AnyStr, Iterable[Union[int, float]]]], *, is_degree: bool = True) → datad.unitcell.UnitCell¶ Initialize a
UnitCell
from array- Parameters
lpArray (array-like) – Array containing six lattice constants
atomsArray (array-like) – Array containing serialized atom information. See
AtomsInCell.from_array
for detailsis_degree (bool, optional) – If True, input angles are in degrees, otherwise in radians. The default value is True.
- Returns
unitcell
- Return type
See also
AtomsInCell.from_array
initialize a AtomsInCell from array
-
static
from_cif
(cifFilePath: AnyStr) → datad.unitcell.UnitCell¶ Initialize a
UnitCell
fromcif
file.- Parameters
cifFilePath (str) – Path of
cif
file.- Returns
unitcell
- Return type
-
static
from_material
(material: AnyStr) → datad.unitcell.UnitCell¶ Initialize a
UnitCell
from material template.- Parameters
material (str) – String standing for a material. Candidates are
Unknown
,Cu
,Ta
,Al
,Mg
,Si
andFe
.- Returns
unitcell
- Return type
-
static
from_structure
(structure: AnyStr, args: Union[Iterable[Any], Dict[str, Any]]) → datad.unitcell.UnitCell¶ Initialize a
UnitCell
from a structure template.- Parameters
structure (str) – String standing for a structure. Candidates are
unknown
,fcc
,bcc
,sc
,hcp
anddiamond
.args (list or dictionary) – Replacer containing values to replace placeholders in structure template.
- Returns
unitcell
- Return type
-
isextinct
(hkls: Union[datad.hkl.HKL, Iterable[datad.hkl.HKL]]) → numpy.ndarray¶ Whether the Miller index triplet is structurally extinct.
- Parameters
hkls (HKL or an array-like of HKL) – Miller index triplet(s).
- Returns
extinct – If True, the corresponding Miller index triplet is extinct.
- Return type
bool or an array of bool
-
property
lattice_matrix
¶ Lattice matrix.
-
property
latticeparameters
¶ Lattice parameters.
-
property
rcp_matrix
¶ Reciprocal lattice matrix.
-
simple_structure_factors_electron
(hkls: Union[datad.hkl.HKL, List[datad.hkl.HKL]]) → numpy.ndarray¶ Approximate structure factors for electrons.
Atomic scattering factors are considered as constant here.
- Parameters
hkls (HKL or an array-like of HKL) – Miller index triplet(s).
- Returns
structure_factors – approximate structure factors.
- Return type
complex or a list of complex
See also
simple_scattering_factors_xray
xray version
scattering_factors_electron
scattering factors considering scattering angles and wavelengthes
-
simple_structure_factors_xray
(hkls: Union[datad.hkl.HKL, List[datad.hkl.HKL]]) → numpy.ndarray¶ Approximate structure factors for X-ray.
Atomic scattering factors are considered as constant here.
- Parameters
hkls (HKL or an array-like of HKL) – Miller index triplet(s).
- Returns
structure_factors – approximate structure factors.
- Return type
complex or a list of complex
See also
simple_scattering_factors_electron
electron version.
scattering_factors_xray
scattering factors considering scattering angles and wavelengthes.
-
structure_factors_electron
(hkls: Union[datad.hkl.HKL, Iterable[datad.hkl.HKL]], *, dulplication: int = 1) → numpy.ndarray¶ Structure factors for electron.
- Parameters
hkls (HKL or an array-like of HKL) – Miller index triplet(s).
dulplication (int, optional) – Dulplication of lattice to calculate scattering factor The default dulplication is 1.
- Returns
structure_factor – structure factors.
- Return type
an array of complex
-
structure_factors_xray
(hkls: Union[datad.hkl.HKL, Iterable[datad.hkl.HKL]], *, vecs: Optional[Union[Iterable[Union[int, float]], Iterable[Iterable[Union[int, float]]]]] = None, dulplication: int = 1) → numpy.ndarray¶ Structure factors for X-ray.
- Parameters
hkls (HKL or an array-like of HKL) – Miller index triplet(s).
vecs (vector or a list of vectors, optional) – If specified, these vectors, rather than the vectors calculated directily from
hkls
, are used to calculate the structure factor.dulplication (int, optional) – Dulplication of lattice to calculate scattering factor. The default dulplication is 1.
- Returns
structure_factors – structure factors
- Return type
an array of complex
-
vec_in_direct
(uvws: Union[datad.hkl.UVW, Iterable[datad.hkl.UVW]], lattice_matrix: Optional[numpy.ndarray] = None, *, convert_to_unit: bool = False) → numpy.ndarray¶ Calculate direct vectors.
- Parameters
uvws (UVW or an array-like of UVW) – Lattice direction index triplet.
direct_matrix (3*3 matrix, optional) – If specified, the input matrix, rather than the lattice matrix of this
UnitCell
, will used to calculate the direct vectors.convert_to_unit (bool, optional) – If True, the output vectors will be normalized. The default value is False.
- Returns
direct_vectors – direct vectors.
- Return type
an array of vectors
-
vecs_in_rcp
(hkls: Union[datad.hkl.HKL, Iterable[datad.hkl.HKL]], rcp_matrix: Optional[numpy.ndarray] = None, *, convert_to_unit: bool = False) → numpy.ndarray¶ Calculate the reciprocal vectors.s
- Parameters
hkls (HKL or an array-like of HKL) – Miller index triplet(s).
rcp_matrix (3*3 matrix or a list of 3*3 matrix, optional) – If specified, the input matrix, rather than the reciprocal matrix of this
UnitCell
, will used to calculate the reciprocal vectors.convert_to_unit (bool, optional) – If True, the output vectors will be normalized. The default value is False.
- Returns
vectors – reciprocal vectors.
- Return type
array of vectors
-
property
-
datad.unitcell.
unitcell_Al
= <Lattice Parameter 4.04600 4.04600 4.04600 90.00 90.00 90.00>'Al' 0.0 0.0 0.0'Al' 0.0 0.5 0.5'Al' 0.5 0.0 0.5'Al' 0.5 0.5 0.0¶ UnitCell
for body-centered cubic Al with lattice parameter 4.406 Angstrom.
-
datad.unitcell.
unitcell_Cu
= <Lattice Parameter 3.61500 3.61500 3.61500 90.00 90.00 90.00>'Cu' 0.0 0.0 0.0'Cu' 0.0 0.5 0.5'Cu' 0.5 0.0 0.5'Cu' 0.5 0.5 0.0¶ UnitCell
for face-centered cubic Cu with lattice parameter 3.615 Angstrom.
-
datad.unitcell.
unitcell_Fe
= <Lattice Parameter 2.86300 2.86300 2.86300 90.00 90.00 90.00>'Fe' 0.0 0.0 0.0'Fe' 0.5 0.5 0.5¶ UnitCell
for body-centered cubic α-Fe with lattice parameter 2.863 Angstrom.
-
datad.unitcell.
unitcell_Mg
= <Lattice Parameter 3.20940 3.20940 5.21050 90.00 90.00 120.00>'Mg' 0.0 0.0 0.0'Mg' 0.3333333333333333 0.6666666666666666 0.5¶ UnitCell
for hexogonal close-packed Mg with lattice parameter a 3.2094 Angstrom and c 5.2105 Angstrom.
-
datad.unitcell.
unitcell_Si
= <Lattice Parameter 5.43050 5.43050 5.43050 90.00 90.00 90.00>'Si' 0.0 0.0 0.0'Si' 0.0 0.5 0.5'Si' 0.25 0.25 0.25'Si' 0.25 0.75 0.75'Si' 0.5 0.0 0.5'Si' 0.5 0.5 0.0'Si' 0.75 0.25 0.75'Si' 0.75 0.75 0.25¶ UnitCell
for diamond structure Si with lattice parameter 5.4305 Angstrom.
-
datad.unitcell.
unitcell_Ta
= <Lattice Parameter 3.30400 3.30400 3.30400 90.00 90.00 90.00>'Ta' 0.0 0.0 0.0'Ta' 0.5 0.5 0.5¶ UnitCell
for body-centered cubic Ta with lattice parameter 3.304 Angstrom.
datad.xray module¶
-
class
datad.xray.
WhiteXray
¶ Bases:
object
White xray with infinite wavelengths and flat intensities. This class is useful for debugging.
Only intensity_xray() method is implemented.
-
intensity_xray
(xray: Union[float, Iterable[float]], *, isWavelength: bool = True, threshold: float = 0.0) → Iterable[float]¶ Intensity of given wavelength
An array filled with value one will be returned.
- Parameters
xray (float or array-like float) – wavelength(es) or energy(ies) to obtain their intensity(ies)
-
-
class
datad.xray.
Xray
(wavelength: Union[float, Iterable[float]], intensity: Optional[Union[float, Iterable[float]]] = None, *, threshold: float = 0)¶ Bases:
object
X-ray spectrum.
- Parameters
wavelength (float or array-like of float) – wavelength(s) of input xray spectrum. Unit is Angstrom.
intensity (float or array-like of float, optionals) – intensity(ies) of input xray spectrum. Unit is arbitrary. If length of input intensity mismatches with length of
wavelength
, a ValueError will be raised.thresold (optional, float) – If specified, the entries with intensities below this threshold will be omited.
-
static
Gaussian
(mu: Union[int, float], sig: Union[int, float], n: int = 100, *, is_wavelength: bool = True) → datad.xray.Xray¶ Returns X-ray with Gaussian-shaped spectrum.
The which difference of center are 5 sigma are truncated.
- Parameters
mu (number) – Center of the gaussian shape.
sig (number) – Sigma(standard deviation) of the gaussian shape.
n (int, optional) – Number of X-ray. The default number is 100.
is_wavelength (bool, optional) – If True, the input
mu
andsig
are wavelength with unit Angstrom. Otherwise, they are both energy with unit keV. The default value is True.
-
Mark
(*, index: Optional[int] = None, wavelength: Optional[float] = None, energy: Optional[float] = None) → None¶ Mark one entry in Xray, which will be emphasized at some places.
Accurate value of wavelength or energy is not needed, the nearest entry will be searched automatically.
- Parameters
index (int, optional) – Index of the entry to be tagged in Xray.
wavelength (float, exclusive with energy, optional) – Wavelength to be tagged in Xray.
energy (float, exclusive with wavelength, optional) – Energy to be tagged in Xray.
-
property
energy
¶ Energy(ies) in keV.
-
static
from_energy
(energy: Union[float, Iterable[float]], intensity: Optional[Union[float, Iterable[float]]] = None, *, thresold: float = 0.0) → datad.xray.Xray¶ Return Xray with spectrum which is represented in energy.
- Parameters
energy (float or array-like of float) – Energy(ies) of spectrum. Unit is keV.
intensity (optional, float or array-like of float) – intensity or intensities of input X-ray spectrum, Unit is Arbitrary. If length of input intensity mismatches with length of
energy
, a ValueError will be raised.thresold (optional, float) – If specified, the entries with intensities below this threshold will be omited.
- Returns
xray
- Return type
-
static
from_file
(filepath: str, *, is_wavelength: bool = True, threshold: float = 0.0, skiprows: int = 0, wavelength_col: int = 0, intensity_col: int = 1, **kwargs) → datad.xray.Xray¶ Read a spectrum from given file and return an
Xray
. np.loadtxt will be used to read spectrum.- Parameters
filepath (str) – Path of file containing spectrum.
is_wavelength (bool, optional) – If True, the given spectrum in in wavlength, otherwise in energy. The default value is True.
thresold (float, optional) – If specified, the entries with intensities below this threshold will be omited.
skiprows (int, optional) – Number of head rows which will be skipped in the file. The default number is zero.
wavelengthcol (int, optional) – Column number for wavelength (or energy) in the file. The default column number is zero.
intensitycol (optional, int) – Column number for intensity in the file. The default column number is one.
kwargs (map) – other keywords arguments will be directly passed to np.loadtxt.
-
static
from_wavelength
(wavelength: Union[float, Iterable[float]], intensity: Optional[Union[float, Iterable[float]]] = None, *, thresold: float = 0) → datad.xray.Xray¶ An alias of Xray().
-
property
intensity
¶ Associated intensity(ies)
-
intensity_xray
(xray: Union[float, Iterable[float]], *, is_wavelength: bool = True, threshold: Optional[float] = None) → Iterable[float]¶ Assiciated intensity(ies) of given wavelength(s) in this spectrum.
The intensity of given wavelegnth is interplated by
np.interp
. In case that the interpolation fails or interplated intensity is below the threshold, the wavelength will be considered not included in the spectrum andNone
will be returned.- Parameters
xray (float or array-like float) – Wavelength(es) or energy(ies) to obtain their intensity(ies)
isWavelength (bool, optional) – If True, the input
xray
is in wavelength. Otherwise the input range is in energy. The default value is True.threshold (float, optional) – If specified, this threshold will be used to omit the entries with low intensities, rather than the
threshold
property in thisXray
.
-
property
is_marked
¶ Whether an entry is marked.
-
mark_in_range
(xmin: Optional[Union[int, float]] = None, xmax: Optional[Union[int, float]] = None, *, is_wavelength: bool = True) → None¶ Mark the entry with largest associated intensity in given range.
- Parameters
xmin (float, optional) – Minimum of the range.
xmax (float, optional) – Maximum of the range.
is_wavelength (bool, optional) – If True, the input
xmin
andxmax
is in wavelength. Otherwise the input range is in energy. The default value is True.
-
property
marked_energy
¶ Marked energy(ies).
-
property
marked_intensity
¶ Associated intensity(ies) of marked entries.
-
property
marked_wavelength
¶ Marked wavelength(s).
-
property
num
¶ Number of the entries.
-
property
number_tag
¶ Number of marked entries.
-
save
(filepath: str, is_wavelength: bool = True)¶ Save X-ray spectrum to file
- Parameters
filepath (str) – Path to file.
is_wavelength (bool, optional) – If True, the saved xray is in wavelength, otherwise in energy. The default value is True.
-
show
(is_wavelength: bool = True, **kwargs) → None¶ Plot to show the spectrum.
- Parameters
is_wavelength (bool, optional) – If True, the x-axis of the plotted figure will be in wavelength. Otherwise the x-axis will be in energy. The default value is True.
kwargs – All keyword arguments passed in will be directly passed to
plt.plot()
.
-
spectrum
(is_wavelength: bool = True) → Tuple[Iterable[float], Iterable[float]]¶ Returns the spectrum of x-ray.
Two np.ndarray are returned, one the wavelengthes or energies and the other the correponding intensities.
- Parameters
is_wavelength (optional, bool) – If True, the first array in returned tuple will be in wavelength. Otherwise, it will be in energy. The default value is True.
- Returns
spectrum – first array is the wavelengthes or energies and the second is the corresponding intensities
- Return type
two np.ndarary
-
property
wavelength
¶ Wavelength(s) in Angstrom.
-
datad.xray.
energyToWavelength
(energy: Union[float, Iterable[float]]) → Iterable[float]¶ Convert energy in keV to wavelength in Angstrom.
-
datad.xray.
lorentzParameters
(tths: Union[float, Iterable[float]]) → numpy.ndarray¶ Lorentz Polarization Factor.
- Parameters
tths (float or an array-like float.) – scattering angle(s) in radian.
- Returns
lp – Lorentz Polarization Factor.
- Return type
an array of float.
-
datad.xray.
wavelengthToEnergy
(wavelength: Union[float, Iterable[float]]) → Iterable[float]¶ Convert wavelength in Angstrom to energy in keV.