xrayutilities package¶
Subpackages¶
 xrayutilities.analysis package
 xrayutilities.io package
 Submodules
 xrayutilities.io.cbf module
 xrayutilities.io.desy_tty08 module
 xrayutilities.io.edf module
 xrayutilities.io.fastscan module
 xrayutilities.io.filedir module
 xrayutilities.io.helper module
 xrayutilities.io.ill_numor module
 xrayutilities.io.imagereader module
 xrayutilities.io.panalytical_xml module
 xrayutilities.io.pdcif module
 xrayutilities.io.rigaku_ras module
 xrayutilities.io.rotanode_alignment module
 xrayutilities.io.seifert module
 xrayutilities.io.spec module
 xrayutilities.io.spectra module
 Module contents
 xrayutilities.materials package
 Submodules
 xrayutilities.materials.atom module
 xrayutilities.materials.cif module
 xrayutilities.materials.database module
 xrayutilities.materials.elements module
 xrayutilities.materials.lattice module
 xrayutilities.materials.material module
 xrayutilities.materials.predefined_materials module
 xrayutilities.materials.spacegrouplattice module
 xrayutilities.materials.wyckpos module
 Module contents
 xrayutilities.math package
 xrayutilities.simpack package
 Submodules
 xrayutilities.simpack.darwin_theory module
 xrayutilities.simpack.fit module
 xrayutilities.simpack.helpers module
 xrayutilities.simpack.models module
 xrayutilities.simpack.mpl_helper module
 xrayutilities.simpack.powder module
 xrayutilities.simpack.powdermodel module
 xrayutilities.simpack.smaterials module
 Module contents
Submodules¶
xrayutilities.config module¶
module to parse xrayutilities userspecific config file the parsed values are provide as global constants for the use in other parts of xrayutilities. The config file with the default constants is found in the python installation path of xrayutilities. It is however not recommended to change things there, instead the userspecific config file ~/.xrayutilities.conf or the local xrayutilities.conf file should be used.
xrayutilities.exception module¶
xrayutilities derives its own exceptions which are raised upon wrong input when calling one of xrayutilities functions. none of the predefined exceptions is made for that purpose.

exception
xrayutilities.exception.
InputError
(msg)[source]¶ Bases:
Exception
Exception raised for errors in the input. Either wrong datatype not handled by TypeError or missing mandatory keyword argument (Note that the obligation to give keyword arguments might depend on the value of the arguments itself)
 Attibutes
 expr – input expression in which the error occurred :msg: – explanation of the error
xrayutilities.experiment module¶
module helping with planning and analyzing experiments. various classes are provided for describing experimental geometries, calculationof angular coordinates of Bragg reflections, conversion of angular coordinates to Qspace and determination of powder diffraction peak positions.
The strength of the module is the versatile QConversion module which can be configured to describe almost any goniometer geometry.

class
xrayutilities.experiment.
Experiment
(ipdir, ndir, **keyargs)[source]¶ Bases:
object
base class for describing experiments users should use the derived classes: HXRD, GID, Powder

Ang2HKL
(*args, **kwargs)[source]¶ angular to (h,k,l) space conversion. It will set the UB argument to Ang2Q and pass all other parameters unchanged. See Ang2Q for description of the rest of the arguments.
Parameters: ****kwargs: optional keyword arguments**
B: reciprocal space conversion matrix of a Crystal. You can specify the matrix B (default identiy matrix) shape needs to be (3,3) mat: Crystal object to use to obtain a B matrix (e.g. xu.materials.Si) can be used as alternative to the B keyword argument B is favored in case both are given U: orientation matrix U can be given. If none is given the orientation defined in the Experiment class is used. dettype: detector type: one of (‘point’, ‘linear’, ‘area’) decides which routine of Ang2Q to call. default ‘point’ delta: giving delta angles to correct the given ones for misalignment. delta must be an numpy array or list of length 2. used angles are than (om,tt)delta wl: xray wavelength in angstroem (default: self._wl) en: xray energy in eV (default: converted self._wl) deg: flag to tell if angles are passed as degree (default: True) sampledis: sample displacement vector in relative units of the detector distance (default: (0, 0, 0)) Returns: H K L coordinates as numpy.ndarray with shape ( * , 3 )
where * corresponds to the number of points given in the input (*args)

TiltAngle
(q, deg=True)[source]¶ TiltAngle(q,deg=True): Return the angle between a qspace position and the surface normal.
Parameters: **q: list or numpy array with the reciprocal space position**
**optional keyword arguments:**
deg: True/False whether the return value should be in degree or radians (default: True)

Transform
(v)[source]¶ transforms a vector, matrix or tensor of rank 4 (e.g. elasticity tensor) to the coordinate frame of the Experiment class. This is for example necessary before any Q2Angconversion can be performed.
Parameters: **v: object to transform, list or numpy array of shape**
(n,) (n,n), (n,n,n,n) where n is the rank of the transformation matrix
Returns: transformed object of the same shape as v

energy
¶

wavelength
¶


class
xrayutilities.experiment.
GID
(idir, ndir, **keyargs)[source]¶ Bases:
xrayutilities.experiment.Experiment
class describing grazing incidence xray diffraction experiments the class helps with calculating the angles of Bragg reflections as well as it helps with analyzing measured data
the class describes a four circle (alpha_i,azimuth,twotheta,beta) goniometer to help with GID experiments at the ROTATING ANODE. 3D data can be treated with the use of linear and area detectors. see help self.Ang2Q
Using this class the default sample surface orientation is determined by the inner most sample rotation (which is usually the azimuth motor).

Ang2Q
(ai, phi, tt, beta, **kwargs)[source]¶ angular to momentum space conversion for a point detector. Also see help GID.Ang2Q for procedures which treat line and area detectors
Parameters: **ai,phi,tt,beta: sample and detector angles as numpy array, lists or**
Scalars must be given. All arguments must have the same shape or length. However, if one angle is always the same its enough to give one scalar value.
****kwargs: optional keyword arguments**
delta: giving delta angles to correct the given ones for misalignment delta must be an numpy array or list of length 4. Used angles are than ai,phi,tt,beta  delta UB: matrix for conversion from (hkl) coordinates to Q of sample used to determine not Q but (hkl) :(default: identity matrix) wl: xray wavelength in angstroem (default: self._wl) deg: flag to tell if angles are passed as degree (default: True) Returns: reciprocal space positions as numpy.ndarray with shape ( * , 3 )
where * corresponds to the number of points given in the input

Q2Ang
(Q, trans=True, deg=True, **kwargs)[source]¶ calculate the GID angles needed in the experiment the inplane reference direction defines the direction were the reference direction is parallel to the primary beam (i.e. lattice planes perpendicular to the beam)
Parameters: **Q: a list or numpy array of shape (3) with**
qspace vector components
**optional keyword arguments:**
trans: True/False apply coordinate transformation on Q deg: True/Flase (default True) determines if the angles are returned in radians or degrees Returns: a numpy array of shape (4) with the four GID scattering angles which
are [alpha_i, azimuth, twotheta, beta]
alpha_i: incidence angle to surface (at the moment always 0) azimuth: sample rotation with respect to the inplane reference direction twotheta: scattering angle beta: exit angle from surface (at the moment always 0)


class
xrayutilities.experiment.
GISAXS
(idir, ndir, **keyargs)[source]¶ Bases:
xrayutilities.experiment.Experiment
class describing grazing incidence xray diffraction experiments the class helps with calculating the angles of Bragg reflections as well as it helps with analyzing measured data
the class describes a three circle (alpha_i,twotheta,beta) goniometer to help with GISAXS experiments at the ROTATING ANODE. 3D data can be treated with the use of linear and area detectors. see help self.Ang2Q

Ang2Q
(ai, tt, beta, **kwargs)[source]¶ angular to momentum space conversion for a point detector. Also see help GISAXS.Ang2Q for procedures which treat line and area detectors
Parameters: **ai,tt,beta: sample and detector angles as numpy array, lists or**
Scalars must be given. all arguments must have the same shape or length. Howevver, if one angle is always the same its enough to give one scalar value.
****kwargs: optional keyword arguments**
delta: giving delta angles to correct the given ones for misalignment delta must be an numpy array or list of length 3. Used angles are than ai,tt,beta  delta UB: matrix for conversion from (hkl) coordinates to Q of sample used to determine not Q but (hkl) :(default: identity matrix) wl: xray wavelength in angstroem (default: self._wl) deg: flag to tell if angles are passed as degree (default: True) Returns: reciprocal space positions as numpy.ndarray with shape ( * , 3 )
where * corresponds to the number of points given in the input


class
xrayutilities.experiment.
HXRD
(idir, ndir, geometry='hi_lo', **keyargs)[source]¶ Bases:
xrayutilities.experiment.Experiment
class describing high angle xray diffraction experiments the class helps with calculating the angles of Bragg reflections as well as helps with analyzing measured data
the class describes a two circle (omega,twotheta) goniometer to help with coplanar xray diffraction experiments. Nevertheless 3D data can be treated with the use of linear and area detectors. see help self.Ang2Q

Ang2Q
(om, tt, **kwargs)[source]¶ angular to momentum space conversion for a point detector. Also see help HXRD.Ang2Q for procedures which treat line and area detectors
Parameters: **om,tt: sample and detector angles as numpy array, lists or**
Scalars must be given. All arguments must have the same shape or length. However, if one angle is always the same its enough to give one scalar value.
****kwargs: optional keyword arguments**
delta: giving delta angles to correct the given ones for misalignment. delta must be an numpy array or list of length 2. Used angles are than om,tt  delta UB: matrix for conversion from (hkl) coordinates to Q of sample used to determine not Q but (hkl) :(default: identity matrix) wl: xray wavelength in angstroem (default: self._wl) deg: flag to tell if angles are passed as degree (default: True) Returns: reciprocal space positions as numpy.ndarray with shape ( * , 3 )
where * corresponds to the number of points given in the input

Q2Ang
(*Q, **keyargs)[source]¶ Convert a reciprocal space vector Q to COPLANAR scattering angles. The keyword argument trans determines whether Q should be transformed to the experimental coordinate frame or not. The coplanar scattering angles correspond to a goniometer with sample rotations [‘x+’,’y+’,’z‘] and detector rotation ‘x+’ and primary beam along y. This is a standard four circle diffractometer.
Parameters: **Q: a list, tuple or numpy array of shape (3) with**
qspace vector components or 3 separate lists with qx,qy,qz
**optional keyword arguments:**
trans: True/False apply coordinate transformation on Q (default True)
deg: True/Flase (default True) determines if the angles are returned in radians or degrees
geometry: determines the scattering geometry:
 “hi_lo” high incidence and low exit
 “lo_hi” low incidence and high exit
 “real” general geometry with angles determined by qcoordinates (azimuth); this and upper geometries return [omega,0,phi,twotheta]
 “realTilt” general geometry with angles determined by qcoordinates (tilt); returns [omega,chi,phi,twotheta]
default: self.geometry refrac: boolean to determine if refraction is taken into account :default: False if True then also a material must be given
mat: Crystal object; needed to obtain its optical properties for refraction correction, otherwise not used
full_output: boolean to determine if additional output is given to determine scattering angles more accurately in case refraction is set to True. default: False
fi,fd: if refraction correction is applied one can optionally specify the facet through which the beam enters (fi) and exits (fd) fi, fd must be the surface normal vectors (not transformed & not necessarily normalized). If omitted the normal direction of the experiment is used.
Returns: a numpy array of shape (4) with four scattering angles which are
[omega,chi,phi,twotheta]
omega: incidence angle with respect to surface chi: sample tilt for the case of noncoplanar geometry phi: sample azimuth with respect to inplane reference direction twotheta: scattering angle/detector angle if full_output:
a numpy array of shape (6) with five angles which are
[omega,chi,phi,twotheta,psi_i,psi_d]
psi_i: offset of the incidence beam from the scattering plane due to refraction pdi_d: offset ot the diffracted beam from the scattering plane due to refraction


class
xrayutilities.experiment.
NonCOP
(idir, ndir, **keyargs)[source]¶ Bases:
xrayutilities.experiment.Experiment
class describing high angle xray diffraction experiments. The class helps with calculating the angles of Bragg reflections as well as helps with analyzing measured data for NONCOPLANAR measurements, where the tilt is used to align asymmetric peaks, like in the case of a polefigure measurement.
The class describes a four circle (omega,twotheta) goniometer to help with xray diffraction experiments. Linear and area detectors can be treated as described in “help self.Ang2Q”

Ang2Q
(om, chi, phi, tt, **kwargs)[source]¶ angular to momentum space conversion for a point detector. Also see help NonCOP.Ang2Q for procedures which treat line and area detectors
Parameters: **om,chi,phi,tt: sample and detector angles as numpy array, lists or**
Scalars must be given. All arguments must have the same shape or length. However, if one angle is always the same its enough to give one scalar value.
****kwargs: optional keyword arguments**
delta: giving delta angles to correct the given ones for misalignment delta must be an numpy array or list of length 4. Used angles are than om,chi,phi,tt  delta UB: matrix for conversion from (hkl) coordinates to Q of sample used to determine not Q but (hkl) :(default: identity matrix) wl: xray wavelength in angstroem (default: self._wl) deg: flag to tell if angles are passed as degree (default: True) Returns: reciprocal space positions as numpy.ndarray with shape ( * , 3 )
where * corresponds to the number of points given in the input

Q2Ang
(*Q, **keyargs)[source]¶ Convert a reciprocal space vector Q to NONCOPLANAR scattering angles. The keyword argument trans determines whether Q should be transformed to the experimental coordinate frame or not.
Parameters: **Q: a list, tuple or numpy array of shape (3) with**
qspace vector components or 3 separate lists with qx,qy,qz
**optional keyword arguments:**
trans: True/False apply coordinate transformation on Q (default True) deg: True/Flase (default True) determines if the angles are returned in radians or degree Returns: a numpy array of shape (4) with four scattering angles which are
[omega, chi, phi, twotheta]
omega: sample rocking angle chi: sample tilt phi: sample azimuth twotheta: scattering angle (detector)


class
xrayutilities.experiment.
PowderExperiment
(**kwargs)[source]¶ Bases:
xrayutilities.experiment.Experiment
Experimental class for powder diffraction which helps to convert theta angles to momentum transfer space

class
xrayutilities.experiment.
QConversion
(sampleAxis, detectorAxis, r_i, **kwargs)[source]¶ Bases:
object
Class for the conversion of angular coordinates to momentum space for arbitrary goniometer geometries and Xray energy. Both angular scans (where some goniometer angles change during data acquisition) and energy scans (where the energy is varied during acquisition) as well as mixed cases can be treated.
the class is configured with the initialization and does provide three distinct routines for conversion to momentum space for
* point detector: point(...) or __call__() * linear detector: linear(...) * area detector: area(...)
linear() and area() can only be used after the init_linear() or init_area() routines were called

UB
¶

area
(*args, **kwargs)[source]¶ angular to momentum space conversion for a area detector the center pixel defined by the init_area routine must be in direction of self.r_i when detector angles are zero
the detector geometry must be initialized by the init_area(...) routine
Parameters: ***args: sample and detector angles as numpy array, lists or**
Scalars in total len(self.sampleAxis)+len(detectorAxis) must be given, always starting with the outer most circle. all arguments must have the same shape or length but can be mixed with Scalars (i.e. if an angle is always the same it can be given only once instead of an array)
sAngles: sample circle angles, number of arguments must correspond to len(self.sampleAxis) dAngles: detector circle angles, number of arguments must correspond to len(self.detectorAxis) ****kwargs: possible keyword arguments**
delta: giving delta angles to correct the given ones for misalignment delta must be an numpy array or list of len(*args). Used angles are than *args  delta UB: matrix for conversion from (hkl) coordinates to Q of sample. Used to determine not Q but (hkl) (default: self.UB) roi: region of interest for the detector pixels; e.g. [100, 900, 200, 800] (default: self._area_roi) Nav: number of channels to average to reduce data size e.g. [2, 2] (default: self._area_nav) wl: xray wavelength in angstroem (default: self._wl) en: xray energy in eV (default is converted self._wl) both wavelength and energy can also be an array which enables the QConversion for energy scans. Note that the en keyword overrules the wl keyword! deg: flag to tell if angles are passed as degree (default: True) sampledis: sample displacement vector in same units as the detector distance (default: (0, 0, 0)) Returns: reciprocal space position of all detector pixels in a numpy.ndarray of
shape ((*)*(self._area_roi[1]  self._area_roi[0]+1) *
(self._area_roi[3]  self._area_roi[2] + 1) , 3) were detectorDir1 is
the fastest varing

detectorAxis
¶ property handler for _detectorAxis
Returns: list of detector axis following the syntax /[xyz][+]/

energy
¶

getDetectorDistance
(*args, **kwargs)[source]¶ obtains the detector distance by applying the detector arm movements. This is especially interesting for the case of 1 or 2D detectors to perform certain geometric corrections.
Parameters: ***args: detector angles. Only detector arm angles as described by the**
detectorAxis attribute must be given.
 **kwargs: optional keyword arguments
dim: dimension of the detector for which the position should be determined roi: region of interest for the detector pixels; :(default: self._area_roi/self._linear_roi) Nav: number of channels to average to reduce data size; :(default: self._area_nav/self._linear_nav) deg: flag to tell if angles are passed as degree (default: True)
Returns: numpy array with the detector distance

getDetectorPos
(*args, **kwargs)[source]¶ obtains the detector position vector by applying the detector arm rotations.
Parameters: ***args: detector angles. Only detector arm angles as described by the**
detectorAxis attribute must be given.
 **kwargs: optional keyword arguments
dim: dimension of the detector for which the position should be determined roi: region of interest for the detector pixels; :(default: self._area_roi/self._linear_roi) Nav: number of channels to average to reduce data size; :(default: self._area_nav/self._linear_nav) deg: flag to tell if angles are passed as degree (default: True)
Returns: numpy array of length 3 with vector components of the detector
direction. The length of the vector is k.

init_area
(detectorDir1, detectorDir2, cch1, cch2, Nch1, Nch2, distance=None, pwidth1=None, pwidth2=None, chpdeg1=None, chpdeg2=None, detrot=0, tiltazimuth=0, tilt=0, **kwargs)[source]¶ initialization routine for area detectors detector direction as well as distance and pixel size or channels per degree must be given. Two separate pixel sizes and channels per degree for the two orthogonal directions can be given
Parameters: **detectorDir1: direction of the detector (along the pixel**
direction 1); e.g. ‘z+’ means higher pixel numbers at larger z positions
detectorDir2: direction of the detector (along the pixel direction 2); e.g. ‘x+’ cch1,2: center pixel, in direction of self.r_i at zero detectorAngles Nch1: number of detector pixels along direction 1 Nch2: number of detector pixels along direction 2 distance: distance of center pixel from center of rotation pwidth1,2: width of one pixel (same unit as distance) chpdeg1,2: channels per degree (only absolute value is relevant) sign determined through detectorDir1,2 detrot: angle of the detector rotation around primary beam direction (used to correct misalignments) tiltazimuth: direction of the tilt vector in the detector plane (in degree) tilt: tilt of the detector plane around an axis normal to the direction given by the tiltazimuth Note
Note: Either distance and pwidth1,2 or chpdeg1,2 must be given !!
Note
Note: the channel numbers run from 0 .. NchX1
****kwargs: optional keyword arguments**
Nav: number of channels to average to reduce data size :(default: [1, 1]) roi: region of interest for the detector pixels; e.g. [100, 900, 200, 800]

init_linear
(detectorDir, cch, Nchannel, distance=None, pixelwidth=None, chpdeg=None, tilt=0, **kwargs)[source]¶ initialization routine for linear detectors detector direction as well as distance and pixel size or channels per degree must be given.
Parameters: **detectorDir: direction of the detector (along the pixel array);**
e.g. ‘z+’
cch: center channel, in direction of self.r_i at zero detectorAngles
Nchannel: total number of detector channels
distance: distance of center channel from center of rotation
pixelwidth: width of one pixel (same unit as distance)
chpdeg: channels per degree (only absolute value is relevant) sign determined through detectorDir
!! Either distance and pixelwidth or chpdeg must be given !!
tilt: tilt of the detector axis from the detectorDir (in degree)
Note
Note: the channel numbers run from 0 .. Nchannel1
****kwargs: optional keyword arguments**
Nav: number of channels to average to reduce data size :(default: 1) roi: region of interest for the detector pixels; e.g. [100,900]

linear
(*args, **kwargs)[source]¶ angular to momentum space conversion for a linear detector the cch of the detector must be in direction of self.r_i when detector angles are zero
the detector geometry must be initialized by the init_linear(...) routine
Parameters: ***args: sample and detector angles as numpy array, lists or**
Scalars in total len(self.sampleAxis)+len(detectorAxis) must be given, always starting with the outer most circle. all arguments must have the same shape or length but can be mixed with Scalars (i.e. if an angle is always the same it can be given only once instead of an array)
sAngles: sample circle angles, number of arguments must correspond to len(self.sampleAxis) dAngles: detector circle angles, number of arguments must correspond to len(self.detectorAxis) ****kwargs: possible keyword arguments**
delta: giving delta angles to correct the given ones for misalignment delta must be an numpy array or list of len(*args) used angles are than *args  delta UB: matrix for conversion from (hkl) coordinates to Q of sample used to determine not Q but (hkl) (default: self.UB) Nav: number of channels to average to reduce data size :(default: self._linear_nav) roi: region of interest for the detector pixels; e.g. [100,900] (default: self._linear_roi) wl: xray wavelength in angstroem (default: self._wl) en: xray energy in eV (default is converted self._wl) both wavelength and energy can also be an array which enables the QConversion for energy scans. Note that the en keyword overrules the wl keyword! deg: flag to tell if angles are passed as degree (default: True) sampledis: sample displacement vector in same units as the detector distance (default: (0, 0, 0)) Returns: reciprocal space position of all detector pixels in a numpy.ndarray of
shape ( (*)*(self._linear_roi[1]self._linear_roi[0]+1) , 3 )

point
(*args, **kwargs)[source]¶ angular to momentum space conversion for a point detector located in direction of self.r_i when detector angles are zero
Parameters: ***args: sample and detector angles as numpy array, lists**
or Scalars in total len(self.sampleAxis)+len(detectorAxis) must be given, always starting with the outer most circle. all arguments must have the same shape or length but can be mixed with Scalars (i.e. if an angle is always the same it can be given only once instead of an array)
sAngles: sample circle angles, number of arguments must correspond to len(self.sampleAxis) dAngles: detector circle angles, number of arguments must correspond to len(self.detectorAxis)  **kwargs: optional keyword arguments
delta: giving delta angles to correct the given ones for misalignment delta must be an numpy array or list of len(*args) used angles are than *args  delta UB: matrix for conversion from (hkl) coordinates to Q of sample used to determine not Q but (hkl) (default: self.UB) wl: xray wavelength in angstroem (default: self._wl) en: xray energy in eV (default is converted self._wl) both wavelength and energy can also be an array which enables the QConversion for energy scans. Note that the en keyword overrules the wl keyword! deg: flag to tell if angles are passed as degree :(default: True) sampledis: sample displacement vector in relative units of the detector distance (default: (0,0,0))
Returns: reciprocal space positions as numpy.ndarray with shape ( * , 3 )
where * corresponds to the number of points given in the input

sampleAxis
¶ property handler for _sampleAxis
Returns: list of sample axis following the syntax /[xyzk][+]/

transformSample2Lab
(vector, *args)[source]¶ transforms a vector from the sample coordinate frame to the laboratory coordinate system by applying the sample rotations from inner to outer circle.
Parameters: **vector: vector to transform (sequence, list, numpy array)**
args: goniometer angles (sample angles or full goniometer angles can be given. If more angles than the sample circles are given they will be ignored) Returns: rotated vector as numpy.array

wavelength
¶

xrayutilities.gridder module¶

class
xrayutilities.gridder.
FuzzyGridder1D
(nx)[source]¶ Bases:
xrayutilities.gridder.Gridder1D
An 1D binning class considering every data point to have a finite width. If necessary one data point will be split fractionally over different data bins. This is numerically more effort but represents better the typical case of a experimental data, which do not represent a mathematical point but have a finite width (e.g. Xray data from a 1D detector).

class
xrayutilities.gridder.
Gridder
[source]¶ Bases:
object
Basis class for gridders in xrayutilities. A gridder is a function mapping irregular spaced data onto a regular grid by binning the data into equally sized elements.
There are different ways of defining the regular grid of a Gridder. In xrayutilities the data bins extend beyond the data range in the input data, but the given position being the center of these bins, extends from the minimum to the maximum of the data! The main motivation for this was to create a Gridder, which when feeded with N equidistant data points and gridded with N bins would not change the data position (not the case with numpy.histogramm functions!). Of course this leads to the fact that for homogeneous point density the first and last bin in any direction are not filled as the other bins.
A different definition is used by numpy histogram functions where the bins extend only to the end of the data range. (see numpy histogram, histrogram2d, ...)

Normalize
(bool)[source]¶ set or unset the normalization flag. Normalization needs to be done to obtain proper gridding but may want to be disabled in certain cases when sequential gridding is performed

data
¶ return gridded data (performs normalization if switched on)


class
xrayutilities.gridder.
Gridder1D
(nx)[source]¶ Bases:
xrayutilities.gridder.Gridder

dataRange
(min, max, fixed=True)[source]¶ define minimum and maximum data range, usually this is deduced from the given data automatically, however, for sequential gridding it is useful to set this before the first call of the gridder. data outside the range are simply ignored
Parameters: **min: minimum value of the gridding range**
max: maximum value of the gridding range fixed: flag to turn fixed range gridding on (True (default)) or off (False)

savetxt
(filename, header='')[source]¶ save gridded data to a txt file with two columns. The first column is the data coordinate and the second the corresponding data value
Parameters: **filename: output filename**
header: optional header for the data file.

xaxis
¶ Returns the xaxis of the gridder the returned values correspond to the center of the data bins used by the gridding algorithm


xrayutilities.gridder.
axis
(min_value, max_value, n)[source]¶ Compute the a grid axis.
Parameters: **min_value ........... axis minimum value**
**max_value ........... axis maximum value**
**n ................... number of steps**

xrayutilities.gridder.
delta
(min_value, max_value, n)[source]¶ Compute the stepsize along an axis of a grid.
Parameters: **min_value ........... axis minimum value**
**max_value ........... axis maximum value**
**n ................... number of steps**

class
xrayutilities.gridder.
npyGridder1D
(nx)[source]¶ Bases:
xrayutilities.gridder.Gridder1D

xaxis
¶ Returns the xaxis of the gridder the returned values correspond to the center of the data bins used by the numpy.histogram function

xrayutilities.gridder2d module¶

class
xrayutilities.gridder2d.
FuzzyGridder2D
(nx, ny)[source]¶ Bases:
xrayutilities.gridder2d.Gridder2D
An 2D binning class considering every data point to have a finite area. If necessary one data point will be split fractionally over different data bins. This is numerically more effort but represents better the typical case of a experimental data, which do not represent a mathematical point but have a finite size (e.g. Xray data from a 2D detector or reciprocal space maps measured with point/linear detector).
Currently only a rectangular area can be considered during the gridding.

class
xrayutilities.gridder2d.
Gridder2D
(nx, ny)[source]¶ Bases:
xrayutilities.gridder.Gridder

SetResolution
(nx, ny)[source]¶ Reset the resolution of the gridder. In this case the original data stored in the object will be deleted.
Parameters: **nx ............ number of points in xdirection**
**ny ............ number of points in ydirection**

dataRange
(xmin, xmax, ymin, ymax, fixed=True)[source]¶ define minimum and maximum data range, usually this is deduced from the given data automatically, however, for sequential gridding it is useful to set this before the first call of the gridder. data outside the range are simply ignored
Parameters: **xmin,ymin: minimum value of the gridding range in x,y**
xmax,ymax: maximum value of the gridding range in x,y fixed: flag to turn fixed range gridding on (True (default)) or off (False)

savetxt
(filename, header='')[source]¶ save gridded data to a txt file with two columns. The first two columns are the data coordinates and the last one the corresponding data value.
Parameters: **filename: output filename**
header: optional header for the data file.

xaxis
¶

xmatrix
¶

yaxis
¶

ymatrix
¶


class
xrayutilities.gridder2d.
Gridder2DList
(nx, ny)[source]¶ Bases:
xrayutilities.gridder2d.Gridder2D
special version of a 2D gridder which performs no actual averaging of the data in one grid/bin but just collects the dataobjects belonging to one bin for further treatment by the user

data
¶ return gridded data, in this special version no normalization is defined!

xrayutilities.gridder3d module¶

class
xrayutilities.gridder3d.
FuzzyGridder3D
(nx, ny, nz)[source]¶ Bases:
xrayutilities.gridder3d.Gridder3D
An 3D binning class considering every data point to have a finite volume. If necessary one data point will be split fractionally over different data bins. This is numerically more effort but represents better the typical case of a experimental data, which do not represent a mathematical point but have a finite size.
Currently only a quader can be considered as volume during the gridding.

class
xrayutilities.gridder3d.
Gridder3D
(nx, ny, nz)[source]¶ Bases:
xrayutilities.gridder.Gridder

dataRange
(xmin, xmax, ymin, ymax, zmin, zmax, fixed=True)[source]¶ define minimum and maximum data range, usually this is deduced from the given data automatically, however, for sequential gridding it is useful to set this before the first call of the gridder. data outside the range are simply ignored
Parameters: **xmin,ymin,zmin: minimum value of the gridding range in x,y,z**
xmax,ymax,zmax: maximum value of the gridding range in x,y,z fixed: flag to turn fixed range gridding on (True (default)) or off (False)

xaxis
¶

xmatrix
¶

yaxis
¶

ymatrix
¶

zaxis
¶

zmatrix
¶

xrayutilities.normalize module¶
module to provide functions that perform block averaging of intensity arrays to reduce the amount of data (mainly for PSD and CCD measurements
and
provide functions for normalizing intensities for
* count time * absorber (userdefined function) * monitor * flatfield correction

class
xrayutilities.normalize.
IntensityNormalizer
(det='', **keyargs)[source]¶ Bases:
object
generic class for correction of intensity (point detector,or MCA, single CCD frames) for count time and absorber factors the class must be supplied with a absorber correction function and works with data structures provided by xrayutilities.io classes or the corresponding objects from hdf5 files

absfun
¶ absfun property handler
returns the costum correction function or None

avmon
¶ av_mon property handler
returns the value of the average monitor or None if average is calculated from the monitor field

darkfield
¶ flatfield property handler
returns the current set darkfield of the detector or None if not set

det
¶ det property handler
returns the detector field name

flatfield
¶ flatfield property handler
returns the current set flatfield of the detector or None if not set

mon
¶ mon property handler
returns the monitor field name or None if not set

time
¶ time property handler
returns the count time or the field name of the count time or None if time is not set


xrayutilities.normalize.
blockAverage1D
(data, Nav)[source]¶ perform block average for 1D array/list of Scalar values all data are used. at the end of the array a smaller cell may be used by the averaging algorithm
Parameters: **data: data which should be contracted (length N)**
Nav: number of values which should be averaged Returns: block averaged numpy array of data type numpy.double
(length ceil(N/Nav))

xrayutilities.normalize.
blockAverage2D
(data2d, Nav1, Nav2, **kwargs)[source]¶ perform a block average for 2D array of Scalar values all data are used therefore the margin cells may differ in size
Parameters: **data2d: array of 2D data shape (N,M)**
Nav1,2: a field of (Nav1 x Nav2) values is contracted ****kwargs: optional keyword argument**
roi: region of interest for the 2D array. e.g. [20,980,40,960] N = 98020; M = 96040 Returns: block averaged numpy array with type numpy.double with shape
( ceil(N/Nav1), ceil(M/Nav2) )

xrayutilities.normalize.
blockAveragePSD
(psddata, Nav, **kwargs)[source]¶ perform a block average for serveral PSD spectra all data are used therefore the last cell used for averaging may differ in size
Parameters: **psddata: array of 2D data shape (Nspectra,Nchannels)**
Nav: number of channels which should be averaged ****kwargs: optional keyword argument**
roi: region of interest for the 2D array. e.g. [20,980] Nchannels = 98020 Returns: block averaged psd spectra as numpy array with type numpy.double
of shape ( Nspectra , ceil(Nchannels/Nav) )
xrayutilities.q2ang_fit module¶
Module provides functions to convert a qvector from reciprocal space to angular space. a simple implementation uses scipy optimize routines to perform a fit for a arbitrary goniometer.
The user is, however, expected to use the bounds variable to put restrictions to the number of free angles to obtain reproducible results. In general only 3 angles are needed to fit an arbitrary qvector (2 sample + 1 detector angles or 1 sample + 2 detector). More complicated restrictions can be implemented using the lmfit package. (done upon request!)
The function is based on a fitting routine. For a specific goniometer also analytic expressions from literature can be used as they are implemented in the predefined experimental classes HXRD, NonCOP, and GID.

xrayutilities.q2ang_fit.
Q2AngFit
(qvec, expclass, bounds=None, ormat=array([[ 1., 0., 0.], [ 0., 1., 0.], [ 0., 0., 1.]]), startvalues=None, constraints=())[source]¶ Functions to convert a qvector from reciprocal space to angular space. This implementation uses scipy optimize routines to perform a fit for a goniometer with arbitrary number of goniometer angles.
The user *must* use the bounds variable to put restrictions to the number of free angles to obtain reproducible results. In general only 3 angles are needed to fit an arbitrary qvector (2 sample + 1 detector angles or 1 sample + 2 detector).
Parameters: **qvec: qvector for which the angular positions should be calculated**
expclass: experimental class used to define the goniometer for which the angles should be calculated.  keyword arguments(optional):
bounds: list of bounds of the goniometer angles. The number of bounds must correspond to the number of goniometer angles in the expclass. Angles can also be fixed by supplying only one value for a particular angle. e.g.: ((low, up), fix, (low2, up2), (low3, up3)) ormat: orientation matrix of the sample to be used in the conversion startvalues: start values for the fit, which can significantly speed up the conversion. The number of values must correspond to the number of angles in the goniometer of the expclass constraints: sequence of constraint dictionaries. This allows applying arbitrary (e.g. pseudoangle) contraints by supplying according constraint functions. (see scipy.optimize.minimize). The supplied function will be called with the arguments (angles, qvec, Experiment, U).
Returns: fittedangles, qerror, errcode:
list of fitted goniometer angles, the error in reciprocal space and the errcode of the scipy minimize function. for a successful fit the error code should be <=2
xrayutilities.utilities module¶
xrayutilities utilities contains a conglomeration of useful functions which do not fit into one of the other files

xrayutilities.utilities.
maplog
(inte, dynlow='config', dynhigh='config', **keyargs)[source]¶ clips values smaller and larger as the given bounds and returns the log10 of the input array. The bounds are given as exponent with base 10 with respect to the maximum in the input array. The function is implemented in analogy to J. Stangl’s matlab implementation.
Parameters: **inte** : numpy.array, values to be cut in range
dynlow: 10^(dynlow) will be the minimum cut off dynhigh: 10^(dynhigh) will be the maximum cut off **optional keyword arguments (NOT IMPLEMENTED):**
abslow: 10^(abslow) will be taken as lower boundary abshigh: 10^(abshigh) will be taken as higher boundary Returns: numpy.array of the same shape as inte, where values smaller/larger then
10^(dynlow,dynhigh) were replaced by 10^(dynlow,dynhigh)
Examples
>>> lint = maplog(int,5,2)
xrayutilities.utilities_noconf module¶
xrayutilities utilities contains a conglomeration of useful functions this part of utilities does not need the config class

xrayutilities.utilities_noconf.
en2lam
(inp)[source]¶ converts the input energy in eV to a wavelength in Angstrom
Parameters: **inp** : energy in eV Returns: float, wavlength in Angstrom Examples
>>> wavelength = en2lam(8048)

xrayutilities.utilities_noconf.
energy
(en)[source]¶ convert common energy names to energies in eV
so far this works with CuKa1, CuKa2, CuKa12, CuKb, MoKa1
Parameters: **en: energy either as scalar or array with value in eV, which**
will be returned unchanged; or string with name of emission line
Returns: energy in eV as float

xrayutilities.utilities_noconf.
exchange_filepath
(orig, new, keep=0)[source]¶ function to exchange the root of a filename with the option of keeping the inner directory structure. This for example includes such a conversion /dir_a/subdir/sample/file.txt > /home/user/data/sample/file.txt where the innermost directory name is kept (keep=1)
Parameters: **orig: original filename which should have its data root replaced**
new: new path which should be used instead keep: (optional) number of inner most directory names which should be kept the same in the output (default = 0). Note that the filename is always return unchanged also with keep=0. Returns: filename string
Examples
>>> exchange_filepath('/dir_a/subdir/sam/file.txt', '/data', 1) '/data/sam/file.txt'

xrayutilities.utilities_noconf.
exchange_path
(orig, new, keep=0)[source]¶ function to exchange the root of a path with the option of keeping the inner directory structure. This for example includes such a conversion /dir_a/subdir/images/sample > /home/user/data/images/sample where the two innermost directory names are kept (keep=2)
Parameters: **orig: original path which should be replaced by the new path**
new: new path which should be used instead keep: (optional) number of inner most directory names which should be kept the same in the output (default = 0) Returns: directory path string
Examples
>>> exchange_path('/dir_a/subdir/img/sam', '/home/user/data', 2) '/home/user/data/img/sam'

xrayutilities.utilities_noconf.
lam2en
(inp)[source]¶ converts the input wavelength in Angstrom to an energy in eV
Parameters: **inp** : wavelength in Angstrom Returns: float, energy in eV Examples
>>> energy = lam2en(1.5406)

xrayutilities.utilities_noconf.
wavelength
(wl)[source]¶ convert common energy names to energies in eV
so far this works with CuKa1, CuKa2, CuKa12, CuKb, MoKa1
Parameters: **wl: wavelength; If scalar or array the wavelength in Angstrom will be**
returned unchanged, string with emission name is converted to wavelength
Returns: wavelength in Angstrom as float
Module contents¶
xrayutilities is a Python package for assisting with xray diffraction experiments. Its the python package included in *xrayutilities*.
It helps with planning experiments as well as analyzing the data.
Authors:  Dominik Kriegner <dominik.kriegner@gmail.com> and Eugen Wintersberger <eugen.wintersberger@desy.de> 
