xrayutilities.io package

Submodules

xrayutilities.io.cbf module

class xrayutilities.io.cbf.CBFDirectory(datapath, ext='cbf', **keyargs)[source]

Bases: FileDirectory

Parses a directory for CBF files, which can be stored to a HDF5 file for further usage

__init__(datapath, ext='cbf', **keyargs)[source]
Parameters:
datapathstr

directory of the CBF files

extstr, optional

extension of the ccd files in the datapath (default: “cbf”)

keyargsdict, optional

further keyword arguments are passed to CBFFile

class xrayutilities.io.cbf.CBFFile(fname, nxkey='X-Binary-Size-Fastest-Dimension', nykey='X-Binary-Size-Second-Dimension', dtkey='DataType', path=None)[source]

Bases: object

ReadData()[source]

Read the CCD data into the .data object this function is called by the initialization

Save2HDF5(h5f, group='/', comp=True)[source]

Saves the data stored in the EDF file in a HDF5 file as a HDF5 array. By default the data is stored in the root group of the HDF5 file - this can be changed by passing the name of a target group or a path to the target group via the “group” keyword argument.

Parameters:
h5ffile-handle or str

a HDF5 file object or name

groupstr, optional

group where to store the data (default to the root of the file)

compbool, optional

activate compression - true by default

__init__(fname, nxkey='X-Binary-Size-Fastest-Dimension', nykey='X-Binary-Size-Second-Dimension', dtkey='DataType', path=None)[source]

CBF detector image parser

Parameters:
fnamestr

name of the CBF file of type .cbf or .cbf.gz

nxkeystr, optional

name of the header key that holds the number of points in x-direction

nykeystr, optional

name of the header key that holds the number of points in y-direction

dtkeystr, optional

name of the header key that holds the datatype for the binary data

pathstr, optional

path to the CBF file

xrayutilities.io.desy_tty08 module

class for reading data + header information from tty08 data files

tty08 is a system used at beamline P08 at Hasylab Hamburg and creates simple ASCII files to save the data. Information is easily read from the multicolumn data file. the functions below enable also to parse the information of the header

xrayutilities.io.desy_tty08.gettty08_scan(scanname, scannumbers, *args, **keyargs)[source]

function to obtain the angular cooridinates as well as intensity values saved in TTY08 datafiles. Especially usefull for reciprocal space map measurements, and to combine date from several scans

further more it is possible to obtain even more positions from the data file if more than two string arguments with its names are given

Parameters:
scannamestr

name of the scans, for multiple scans this needs to be a template string

scannumbersint, tuple or list

number of the scans of the reciprocal space map

argsstr, optional

names of the motors. to read reciprocal space maps measured in coplanar diffraction give:

  • omname: the name of the omega motor (or its equivalent)

  • ttname: the name of the two theta motor (or its equivalent)

keyargsdict, optional

keyword arguments are passed on to tty08File

Returns:
[ang1, ang2, …]list, optional

angular positions of the center channel of the position sensitive detector (numpy.ndarray 1D), omitted if no args are given

MAPndarray

All the data values as stored in the data file (includes the intensities e.g. MAP[‘MCA’]).

Examples

>>> [om, tt], MAP = xu.io.gettty08_scan('text%05d.dat', 36, 'omega',
... 'gamma')  
class xrayutilities.io.desy_tty08.tty08File(filename, path=None, mcadir=None)[source]

Bases: object

Represents a tty08 data file. The file is read during the Constructor call. This class should work for data stored at beamline P08 using the tty08 acquisition system.

Parameters:
filenamestr

tty08-filename

mcadirstr, optional

directory name of MCA files

Read()[source]

Read the data from the file

ReadMCA()[source]
__init__(filename, path=None, mcadir=None)[source]

xrayutilities.io.edf module

class xrayutilities.io.edf.EDFDirectory(datapath, ext='edf', **keyargs)[source]

Bases: FileDirectory

Parses a directory for EDF files, which can be stored to a HDF5 file for further usage

__init__(datapath, ext='edf', **keyargs)[source]
Parameters:
datapathstr

directory of the EDF file

extstr, optional

extension of the ccd files in the datapath (default: “edf”)

keyargsdict, optional

further keyword arguments are passed to EDFFile

class xrayutilities.io.edf.EDFFile(fname, nxkey='Dim_1', nykey='Dim_2', dtkey='DataType', path='', header=True, keep_open=False)[source]

Bases: object

Parse()[source]

Parse file to find the number of entries and read the respective header information

ReadData(nimg=0)[source]

Read the CCD data of the specified image and return the data this function is called automatically when the ‘data’ property is accessed, but can also be called manually when only a certain image from the file is needed.

Parameters:
nimgint, optional

number of the image which should be read (starts with 0)

Save2HDF5(h5f, group='/', comp=True)[source]

Saves the data stored in the EDF file in a HDF5 file as a HDF5 array. By default the data is stored in the root group of the HDF5 file - this can be changed by passing the name of a target group or a path to the target group via the “group” keyword argument.

Parameters:
h5ffile-handle or str

a HDF5 file object or name

groupstr, optional

group where to store the data (default to the root of the file)

compbool, optional

activate compression - true by default

__init__(fname, nxkey='Dim_1', nykey='Dim_2', dtkey='DataType', path='', header=True, keep_open=False)[source]
Parameters:
fnamestr

name of the EDF file of type .edf or .edf.gz

nxkeystr, optional

name of the header key that holds the number of points in x-direction

nykeystr, optional

name of the header key that holds the number of points in y-direction

dtkeystr, optional

name of the header key that holds the datatype for the binary data

pathstr, optional

path to the EDF file

headerbool, optional

has header (default true)

keep_openbool, optional

if True the file handle is kept open between multiple calls which can cause significant speed-ups

property data

xrayutilities.io.fastscan module

modules to help with the analysis of FastScan data acquired at the ESRF. FastScan data are X-ray data (various detectors possible) acquired during scanning the sample in real space with a Piezo Scanner. The same functions might be used to analze traditional SPEC mesh scans.

The module provides three core classes:

  • FastScan

  • FastScanCCD

  • FastScanSeries

where the first two are able to parse single mesh/FastScans when one is interested in data of a single channel detector or are detector and the last one is able to parse full series of such mesh scans with either type of detector

see examples/xrayutilities_kmap_ESRF.py for an example script

class xrayutilities.io.fastscan.FastScan(filename, scannr, xmotor='adcX', ymotor='adcY', path='')[source]

Bases: object

class to help parsing and treating fast scan data. FastScan is the aquisition of X-ray data while scanning the sample with piezo stages in real space. It’s is available at several beamlines at the ESRF synchrotron light-source.

__init__(filename, scannr, xmotor='adcX', ymotor='adcY', path='')[source]

Constructor routine for the FastScan object. It initializes the object and parses the spec-scan for the needed data which are saved in properties of the FastScan object.

Parameters:
filenamestr

file name of the fast scan spec file

scannrint

scannr of the to be parsed fast scan

xmotorstr, optional

motor name of the x-motor (default: ‘adcX’ (ID01))

ymotorstr, optional

motor name of the y-motor (default: ‘adcY’ (ID01))

pathstr, optional

optional path of the FastScan spec file

grid2D(nx, ny, **kwargs)[source]

function to grid the counter data and return the gridded X, Y and Intensity values.

Parameters:
nx, nyint

number of bins in x, and y direction

counterstr, optional

name of the counter to use for gridding (default: ‘mpx4int’ (ID01))

gridrangetuple, optional

range for the gridder: format: ((xmin, xmax), (ymin, ymax))

Returns:
Gridder2D

Gridder2D object with X, Y, data on regular x, y-grid

motorposition(motorname)[source]

read the position of motor with name given by motorname from the data file. In case the motor is included in the data columns the returned object is an array with all the values from the file (although retrace clean is respected if already performed). In the case the motor is not moved during the scan only one value is returned.

Parameters:
motornamestr

name of the motor for which the position is wanted

Returns:
ndarray

motor position(s) of motor with name motorname during the scan

parse()[source]

parse the specfile for the scan number specified in the constructor and store the needed informations in the object properties

retrace_clean()[source]

function to clean the data of the scan from retrace artifacts created by the zig-zag scanning motion of the piezo actuators the function cleans the xvalues, yvalues and data attribute of the FastScan object.

class xrayutilities.io.fastscan.FastScanCCD(*args, **kwargs)[source]

Bases: FastScan

class to help parsing and treating fast scan data including CCD frames. FastScan is the aquisition of X-ray data while scanning the sample with piezo stages in real space. It’s is available at several beamlines at the ESRF synchrotron light-source. During such fast scan at every grid point CCD frames are recorded and need to be analyzed

__init__(*args, **kwargs)[source]
Parameters:
imagefiletypestr, optional

image file extension, either ‘edf’ / ‘edf.gz’ (default) or ‘h5’

other parameters are passed on to FastScanCCD
getCCD(ccdnr, roi=None, datadir=None, keepdir=0, replacedir=None, nav=(1, 1), filterfunc=None)[source]

function to read the ccd files and return the raw X, Y and DATA values. DATA represents a 3D object with first dimension representing the data point index and the remaining two dimensions representing detector channels

Parameters:
ccdnrarray-like or str

array with ccd file numbers of length length(FastScanCCD.data) OR a string with the data column name for the file ccd-numbers

roituple, optional

region of interest on the 2D detector. should be a list of lower and upper bounds of detector channels for the two pixel directions (default: None)

datadirstr, optional

the CCD filenames are usually parsed from the SPEC file. With this option the directory used for the data can be overwritten. Specify the datadir as simple string. Alternatively the innermost directory structure can be automatically taken from the specfile. If this is needed specify the number of directories which should be kept using the keepdir option.

keepdirint, optional

number of directories which should be taken from the SPEC file. (default: 0)

replacedirint, optional

number of outer most directory names which should be replaced in the output (default = None). One can either give keepdir, or replacedir, with replace taking preference if both are given.

navtuple or list, optional

number of detector pixel which will be averaged together (reduces the date size)

filterfunccallable

function applied to the CCD-frames before any processing. this function should take a single argument which is the ccddata which need to be returned with the same shape! e.g. remove hot pixels, flat/darkfield correction

Returns:
X, Yndarray

x, y-array (1D)

DATAndarray

3-dimensional data object

getccdFileTemplate(specscan, datadir=None, keepdir=0, replacedir=None)[source]

function to extract the CCD file template string from the comment in the SPEC-file scan-header.

Parameters:
specscanSpecScan

spec-scan object from which header the CCD directory should be extracted

datadirstr, optional

the CCD filenames are usually parsed from the scan object. With this option the directory used for the data can be overwritten. Specify the datadir as simple string. Alternatively the innermost directory structure can be automatically taken from the specfile. If this is needed specify the number of directories which should be kept using the keepdir option.

keepdirint, optional

number of directories which should be taken from the specscan. (default: 0)

replacedirint, optional

number of outer most directory names which should be replaced in the output (default = None). One can either give keepdir, or replacedir, with replace taking preference if both are given.

Returns:
fmtstrstr

format string for the CCD file name using one number to build the real file name

filenrint

starting file number

gridCCD(nx, ny, ccdnr, roi=None, datadir=None, keepdir=0, replacedir=None, nav=(1, 1), gridrange=None, filterfunc=None)[source]

function to grid the internal data and ccd files and return the gridded X, Y and DATA values. DATA represents a 4D object with first two dimensions representing X, Y and the remaining two dimensions representing detector channels

Parameters:
nx, nyint

number of bins in x, and y direction

ccdnrarray-like or str

array with ccd file numbers of length length(FastScanCCD.data) OR a string with the data column name for the file ccd-numbers

roituple, optional

region of interest on the 2D detector. should be a list of lower and upper bounds of detector channels for the two pixel directions (default: None)

datadirstr, optional

the CCD filenames are usually parsed from the SPEC file. With this option the directory used for the data can be overwritten. Specify the datadir as simple string. Alternatively the innermost directory structure can be automatically taken from the specfile. If this is needed specify the number of directories which should be kept using the keepdir option.

keepdirint, optional

number of directories which should be taken from the SPEC file. (default: 0)

replacedirint, optional

number of outer most directory names which should be replaced in the output (default = None). One can either give keepdir, or replacedir, with replace taking preference if both are given.

navtuple or list, optional

number of detector pixel which will be averaged together (reduces the date size)

gridrangetuple

range for the gridder: format: ((xmin, xmax), (ymin, ymax))

filterfunccallable

function applied to the CCD-frames before any processing. this function should take a single argument which is the ccddata which need to be returned with the same shape! e.g. remove hot pixels, flat/darkfield correction

Returns:
X, Y: ndarray

regular x, y-grid

DATAndarray

4-dimensional data object

processCCD(ccdnr, roi, datadir=None, keepdir=0, replacedir=None, filterfunc=None)[source]

function to read a region of interest (ROI) from the ccd files and return the raw X, Y and intensity from ROI.

Parameters:
ccdnrarray-like or str

array with ccd file numbers of length length(FastScanCCD.data) OR a string with the data column name for the file ccd-numbers

roituple or list

region of interest on the 2D detector. Either a list of lower and upper bounds of detector channels for the two pixel directions as tuple or a list of mask arrays

datadirstr, optional

the CCD filenames are usually parsed from the SPEC file. With this option the directory used for the data can be overwritten. Specify the datadir as simple string. Alternatively the innermost directory structure can be automatically taken from the specfile. If this is needed specify the number of directories which should be kept using the keepdir option.

keepdirint, optional

number of directories which should be taken from the SPEC file. (default: 0)

replacedirint, optional

number of outer most directory names which should be replaced in the output (default = None). One can either give keepdir, or replacedir, with replace taking preference if both are given.

filterfunccallable, optional

function applied to the CCD-frames before any processing. this function should take a single argument which is the ccddata which need to be returned with the same shape! e.g. remove hot pixels, flat/darkfield correction

Returns:
X, Y, DATAndarray

x, y-array (1D) as well as 1-dimensional data object

class xrayutilities.io.fastscan.FastScanSeries(filenames, scannrs, nx, ny, *args, **kwargs)[source]

Bases: object

class to help parsing and treating a series of fast scan data including CCD frames. FastScan is the aquisition of X-ray data while scanning the sample with piezo stages in real space. It’s is available at several beamlines at the ESRF synchrotron light-source. During such fast scan at every grid point CCD frames are recorded and need to be analyzed.

For the series of FastScans we assume that they are measured at different goniometer angles and therefore transform the data to reciprocal space.

__init__(filenames, scannrs, nx, ny, *args, **kwargs)[source]

Constructor routine for the FastScanSeries object. It initializes the object and creates a list of FastScanCCD objects. Importantly it also expects the motor names of the angles needed for reciprocal space conversion.

Parameters:
filenameslist or str

file names of the fast scan spec files, in case of more than one filename supply a list of names and also a list of scan numbers for the different files in the ‘scannrs’ argument

scannrslist

scannrs of the to be parsed fast scans. in case of one specfile this is a list of numbers (e.g. [1, 2, 3]). when multiple filenames are given supply a separate list for every file (e.g. [[1, 2, 3],[2, 4]])

nx, nyint

grid-points for the real space grid

argsstr

motor names for the Reciprocal space conversion. The order needs be as required by the QConversion.area() function.

xmotorstr, optional

motor name of the x-motor (default: ‘adcX’ (ID01))

ymotorstr, optional

motor name of the y-motor (default: ‘adcY’ (ID01))

ccdnrstr, optional

name of the ccd-number data column (default: ‘imgnr’ (ID01))

counterstr, optional

name of a defined counter (roi) in the spec file (default: ‘mpx4int’ (ID01))

pathstr, optional

path of the FastScan spec file (default: ‘’)

align(deltax, deltay)[source]

Since a sample drift or shift due to rotation often occurs between different FastScans it should be corrected before combining them. Since determining such a shift is not straight-forward in general the user needs to supply the routine with the shifts in order correct the x, y-values for the different FastScans. Such a routine could for example use the integrated CCD intensities and determine the shift using a cross-convolution.

Parameters:
deltax, deltaylist

list of shifts in x/y-direction for every FastScan in the data structure

getCCDFrames(posx, posy, typ='real')[source]

function to determine the list of ccd-frame numbers for a specific real space position. The real space position must be within the data limits of the FastScanSeries otherwise an ValueError is thrown

Parameters:
posxfloat

real space x-position or index in x direction

posyfloat

real space y-position or index in y direction

typ{‘real’, ‘index’}, optional

type of coordinates. specifies if the position is specified as real space coordinate or as index. (default: ‘real’)

Returns:
list

[[motorpos1, ccdnrs1], [motorpos2, ccdnrs2], ...] where motorposN is from the N-ths FastScan in the series and ccdnrsN is the list of according CCD-frames

get_average_RSM(qnx, qny, qnz, qconv, datadir=None, keepdir=0, replacedir=None, roi=None, nav=(1, 1), filterfunc=None)[source]

function to return the reciprocal space map data averaged over all x, y positions from a series of FastScan measurements. It necessary to give the QConversion-object to be used for the reciprocal space conversion. The QConversion-object is expected to have the ‘area’ conversion routines configured properly. This function needs to read all detector images, so be prepared to lean back for a moment!

Parameters:
qnx, qny, qnzint

number of points used for the 3D Gridder

qconvQConversion

QConversion-object to be used for the conversion of the CCD-data to reciprocal space

roituple, optional

region of interest on the 2D detector. should be a list of lower and upper bounds of detector channels for the two pixel directions (default: None)

navtuple or list, optional

number of detector pixel which will be averaged together (reduces the date size)

filterfunccallable, optional

function applied to the CCD-frames before any processing. this function should take a single argument which is the ccddata which need to be returned with the same shape! e.g. remove hot pixels, flat/darkfield correction

datadirstr, optional

the CCD filenames are usually parsed from the SPEC file. With this option the directory used for the data can be overwritten. Specify the datadir as simple string. Alternatively the innermost directory structure can be automatically taken from the specfile. If this is needed specify the number of directories which should be kept/replaced using the keepdir/replacedir option.

keepdirint, optional

number of directories which should be taken from the SPEC file. (default: 0)

replacedirint, optional

number of outer most directory names which should be replaced in the output (default = None). One can either give keepdir, or replacedir, with replace taking preference if both are given.

Returns:
Gridder3D

gridded reciprocal space map

get_sxrd_for_qrange(qrange, qconv, datadir=None, keepdir=0, replacedir=None, roi=None, nav=(1, 1), filterfunc=None)[source]

function to return the real space data averaged over a certain q-range from a series of FastScan measurements. It necessary to give the QConversion-object to be used for the reciprocal space conversion. The QConversion-object is expected to have the ‘area’ conversion routines configured properly.

Note

This function assumes that all FastScans were performed in the same real space positions, no gridding or aligning is performed!

Parameters:
qrangelist or tuple

q-limits defining a box in reciprocal space. six values are needed: [minx, maxx, miny, …, maxz]

qconvQConversion

QConversion object to be used for the conversion of the CCD-data to reciprocal space

roituple, optional

region of interest on the 2D detector. should be a list of lower and upper bounds of detector channels for the two pixel directions (default: None)

navtuple or list, optional

number of detector pixel which will be averaged together (reduces the date size)

filterfunccallable, optional

function applied to the CCD-frames before any processing. this function should take a single argument which is the ccddata which need to be returned with the same shape! e.g. remove hot pixels, flat/darkfield correction

datadirstr, optional

the CCD filenames are usually parsed from the SPEC file. With this option the directory used for the data can be overwritten. Specify the datadir as simple string. Alternatively the innermost directory structure can be automatically taken from the specfile. If this is needed specify the number of directories which should be kept/replaced using the keepdir/replacedir option.

keepdirint, optional

number of directories which should be taken from the SPEC file. (default: 0)

replacedirint, optional

number of outer most directory names which should be replaced in the output (default = None). One can either give keepdir, or replacedir, with replace taking preference if both are given.

Returns:
xvalues, yvalues, datandarray

x, y, and data values

grid2Dall(nx, ny, **kwargs)[source]

function to grid the counter data and return the gridded X, Y and Intensity values from all the FastScanSeries.

Parameters:
nx, nyint

number of bins in x, and y direction

counterstr, optional

name of the counter to use for gridding (default: ‘mpx4int’ (ID01))

gridrangetuple, optional

range for the gridder: format: ((xmin, xmax), (ymin, ymax))

Returns:
Gridder2D

object with X, Y, data on regular x, y-grid

gridRSM(posx, posy, qnx, qny, qnz, qconv, roi=None, nav=(1, 1), typ='real', filterfunc=None, **kwargs)[source]

function to calculate the reciprocal space map at a certain x, y-position from a series of FastScan measurements it is necessary to specify the number of grid-oints for the reciprocal space map and the QConversion-object to be used for the reciprocal space conversion. The QConversion-object is expected to have the ‘area’ conversion routines configured properly.

Parameters:
posxfloat

real space x-position or index in x direction

posyfloat

real space y-position or index in y direction

qnx, qny, qnzint

number of points in the Qx, Qy, Qz direction of the gridded reciprocal space map

qconvQConversion

QConversion-object to be used for the conversion of the CCD-data to reciprocal space

roituple, optional

region of interest on the 2D detector. should be a list of lower and upper bounds of detector channels for the two pixel directions (default: None)

navtuple or list, optional

number of detector pixel which will be averaged together (reduces the date size)

typ{‘real’, ‘index’}, optional

type of coordinates. specifies if the position is specified as real space coordinate or as index. (default: ‘real’)

filterfunccallable, optional

function applied to the CCD-frames before any processing. this function should take a single argument which is the ccddata which need to be returned with the same shape! e.g. remove hot pixels, flat/darkfield correction

UBndarray

sample orientation matrix

Returns:
Gridder3D

object with gridded reciprocal space map

rawRSM(posx, posy, qconv, roi=None, nav=(1, 1), typ='real', datadir=None, keepdir=0, replacedir=None, filterfunc=None, **kwargs)[source]

function to return the reciprocal space map data at a certain x, y-position from a series of FastScan measurements. It necessary to give the QConversion-object to be used for the reciprocal space conversion. The QConversion-object is expected to have the ‘area’ conversion routines configured properly.

Parameters:
posxfloat

real space x-position or index in x direction

posyfloat

real space y-position or index in y direction

qconvQConversion

QConversion-object to be used for the conversion of the CCD-data to reciprocal space

roituple, optional

region of interest on the 2D detector. should be a list of lower and upper bounds of detector channels for the two pixel directions (default: None)

navtuple or list, optional

number of detector pixel which will be averaged together (reduces the date size)

typ{‘real’, ‘index’}, optional

type of coordinates. specifies if the position is specified as real space coordinate or as index. (default: ‘real’)

filterfunccallable, optional

function applied to the CCD-frames before any processing. this function should take a single argument which is the ccddata which need to be returned with the same shape! e.g. remove hot pixels, flat/darkfield correction

UBarray-like, optional

sample orientation matrix

datadirstr, optional

the CCD filenames are usually parsed from the SPEC file. With this option the directory used for the data can be overwritten. Specify the datadir as simple string. Alternatively the innermost directory structure can be automatically taken from the specfile. If this is needed specify the number of directories which should be kept using the keepdir option.

keepdirint, optional

number of directories which should be taken from the SPEC file. (default: 0)

replacedirint, optional

number of outer most directory names which should be replaced in the output (default = None). One can either give keepdir, or replacedir, with replace taking preference if both are given.

Returns:
qx, qy, qzndarray

reciprocal space positions of the reciprocal space map

ccddatandarray

raw data of the reciprocal space map

valuelistndarray

valuelist containing the ccdframe numbers and corresponding motor positions

read_motors()[source]

read motor values from the series of fast scans

retrace_clean()[source]

perform retrace clean for every FastScan in the series

xrayutilities.io.filedir module

class xrayutilities.io.filedir.FileDirectory(datapath, ext, parser, **keyargs)[source]

Bases: object

Parses a directory for files, which can be stored to a HDF5 file for further usage. The file parser is given to the constructor and must provide a Save2HDF5 method.

Save2HDF5(h5f, group='', comp=True)[source]

Saves the data stored in the found files in the specified directory in a HDF5 file as a HDF5 arrays in a subgroup. By default the data is stored in a group given by the foldername - this can be changed by passing the name of a target group or a path to the target group via the “group” keyword argument.

Parameters:
h5ffile-handle or str

a HDF5 file object or name

groupstr, optional

group where to store the data (defaults to pathname if group is empty string)

compbool, optional

activate compression - true by default

__init__(datapath, ext, parser, **keyargs)[source]
Parameters:
datapathstr

directory of the files

extstr

extension of the files in the datapath

parserclass

Parser class for the data files.

keyargsdict

further keyword arguments are passed to the constructor of the parser

xrayutilities.io.helper module

convenience functions to open files for various data file reader

these functions should be used in new parsers since they transparently allow to open gzipped and bzipped files

xrayutilities.io.helper.generate_filenames(filetemplate, scannrs=None)[source]

generate a list of filenames from a template and replacement values.

Parameters:
filetemplate: str or list

template string which should contain placeholders if scannrs is not None

scannrs: iterable, optional

list of scan numbers. If None then the filetemplate will be returned.

Returns:
list of filenames. If only a single filename is returned it will still be
encapsulated in a list

Examples

>>> generate_filenames("filename_%d.ras", [1, 2, 3])
['filename_1.ras', 'filename_2.ras', 'filename_3.ras']
>>> generate_filenames("filename_{}.ras", [1, 2, 3])
['filename_1.ras', 'filename_2.ras', 'filename_3.ras']
>>> generate_filenames("filename_{}_{}.ras", [(11, 1), (21, 2), (31, 3)])
['filename_11_1.ras', 'filename_21_2.ras', 'filename_31_3.ras']
>>> generate_filenames("filename_%d.ras", 1)
['filename_1.ras']
>>> generate_filenames("filename.ras")
['filename.ras']
>>> generate_filenames(["filename.ras", "othername.ras"])
['filename.ras', 'othername.ras']
class xrayutilities.io.helper.xu_h5open(f, mode='r')[source]

Bases: object

helper object to decide if a HDF5 file has to be opened/closed when using with a ‘with’ statement.

__init__(f, mode='r')[source]
Parameters:
fstr

filename or h5py.File instance

modestr, optional

mode in which the file should be opened. ignored in case a file handle is passed as f

xrayutilities.io.helper.xu_open(filename, mode='rb')[source]

function to open a file no matter if zipped or not. Files with extension ‘.gz’, ‘.bz2’, and ‘.xz’ are assumed to be compressed and transparently opened to read like usual files.

Parameters:
filenamestr or bytes

filename of the file to open or a bytes-stream with the file contents

modestr, optional

mode in which the file should be opened

Returns:
file-handle

handle of the opened file

Raises:
IOError

If the file does not exist an IOError is raised by the open routine, which is not caught within the function

xrayutilities.io.ill_numor module

module for reading ILL data files (station D23): numor files

class xrayutilities.io.ill_numor.numorFile(filename, path=None)[source]

Bases: object

Represents a ILL data file (numor). The file is read during the Constructor call. This class should work for created at station D23 using the mad acquisition system.

Parameters:
filenamestr

a string with the name of the data file

Read()[source]

Read the data from the file

__init__(filename, path=None)[source]

constructor for the data file parser

Parameters:
filenamestr

a string with the name of the data file

pathstr, optional

directory of the data file

columns = {0: ('detector', 'monitor', 'time', 'gamma', 'omega', 'psi'), 1: ('detector', 'monitor', 'time', 'gamma'), 2: ('detector', 'monitor', 'time', 'omega'), 5: ('detector', 'monitor', 'time', 'psi')}
getline(fid)[source]
ssplit(string)[source]

multispace split. splits string at two or more spaces after stripping it.

xrayutilities.io.ill_numor.numor_scan(scannumbers, *args, **kwargs)[source]

function to obtain the angular cooridinates as well as intensity values saved in numor datafiles. Especially useful for combining several scans into one data object.

Parameters:
scannumbersint or str or iterable

number of the numors, or list of numbers. This will be transformed to a string and used as a filename

argsstr, optional

names of the motors e.g.: ‘omega’, ‘gamma’

kwargsdict

keyword arguments are passed on to numorFile. e.g. ‘path’ for the files directory

Returns:
[ang1, ang2, …]list

angular positions list, omitted if no args are given

datandarray

all the data values.

Examples

>>> [om, gam], data = xu.io.numor_scan(414363, 'omega', 'gamma')    

xrayutilities.io.imagereader module

class xrayutilities.io.imagereader.ImageReader(nop1, nop2, hdrlen=0, flatfield=None, darkfield=None, dtype=<class 'numpy.int16'>, byte_swap=False)[source]

Bases: object

parse CCD frames in the form of tiffs or binary data (*.bin) to numpy arrays. ignore the header since it seems to contain no useful data

The routine was tested so far with

  1. RoperScientific files with 4096x4096 pixels created at Hasylab Hamburg, which save an 16bit integer per point.

  2. Perkin Elmer images created at Hasylab Hamburg with 2048x2048 pixels.

__init__(nop1, nop2, hdrlen=0, flatfield=None, darkfield=None, dtype=<class 'numpy.int16'>, byte_swap=False)[source]

initialize the ImageReader reader, which includes setting the dimension of the images as well as defining the data used for flat- and darkfield correction!

Parameters:
nop1, nop2int

number of pixels in the first and second dimension of the image

hdrlenint, optional

length of the file header which should be ignored

flatfieldstr or ndarray, optional

filename or data for flatfield correction. supported file types include (.bin/.tif (also compressed .xz or .gz) and .npy files). otherwise a 2D numpy array should be given

darkfieldstr or ndarray, optional

filename or data for darkfield correction. same types as for flat field are supported.

dtypenumpy.dtype, optional

datatype of the stored values (default: numpy.int16)

byte_swapbool, optional

flag which determines bytes are swapped after reading

readImage(filename, path=None)[source]

read image file and correct for dark- and flatfield in case the necessary data are available.

returned data = ((image data)-(darkfield))/flatfield*average(flatfield)

Parameters:
filenamestr

filename of the image to be read. so far only single filenames are supported. The data might be compressed. supported extensions: .tif, .bin and .bin.xz

pathstr, optional

path of the data files

class xrayutilities.io.imagereader.PerkinElmer(**keyargs)[source]

Bases: ImageReader

parse PerkinElmer CCD frames (*.tif) to numpy arrays Ignore the header since it seems to contain no useful data

The routine was tested only for files with 2048x2048 pixel images created at Hasylab Hamburg which save an 32bit float per point.

__init__(**keyargs)[source]

initialize the PerkinElmer reader, which includes setting the dimension of the images as well as defining the data used for flat- and darkfield correction!

Parameters:
flatfieldstr or ndarray, optional

filename or data for flatfield correction. supported file types include (.bin .bin.xz and .npy files). otherwise a 2D numpy array should be given

darkfieldstr or ndarray, optional

filename or data for darkfield correction. same types as for flat field are supported.

class xrayutilities.io.imagereader.Pilatus100K(**keyargs)[source]

Bases: ImageReader

parse Dectris Pilatus 100k frames (*.tiff) to numpy arrays Ignore the header since it seems to contain no useful data

__init__(**keyargs)[source]

initialize the Piulatus100k reader, which includes setting the dimension of the images as well as defining the data used for flat- and darkfield correction!

Parameters:
flatfieldstr or ndarray, optional

filename or data for flatfield correction. supported file types include (.bin .bin.xz and .npy files). otherwise a 2D numpy array should be given

darkfieldstr or ndarray, optional

filename or data for darkfield correction. same types as for flat field are supported.

class xrayutilities.io.imagereader.RoperCCD(**keyargs)[source]

Bases: ImageReader

parse RoperScientific CCD frames (*.bin) to numpy arrays Ignore the header since it seems to contain no useful data

The routine was tested only for files with 4096x4096 pixel images created at Hasylab Hamburg which save an 16bit integer per point.

__init__(**keyargs)[source]

initialize the RoperCCD reader, which includes setting the dimension of the images as well as defining the data used for flat- and darkfield correction!

Parameters:
flatfieldstr or ndarray, optional

filename or data for flatfield correction. supported file types include (.bin .bin.xz and .npy files). otherwise a 2D numpy array should be given

darkfieldstr or ndarray, optional

filename or data for darkfield correction. same types as for flat field are supported.

class xrayutilities.io.imagereader.TIFFRead(filename, path=None)[source]

Bases: ImageReader

class to Parse a TIFF file including extraction of information from the file header in order to determine the image size and data type

The data stored in the image are available in the ‘data’ property.

__init__(filename, path=None)[source]

initialization of the class which will prepare the parser and parse the files content into class properties

Parameters:
filenamestr

file name of the TIFF-like image file

pathstr, optional

path of the data file

xrayutilities.io.imagereader.get_tiff(filename, path=None)[source]

read tiff image file and return the data

Parameters:
filenamestr

filename of the image to be read. so far only single filenames are supported. The data might be compressed.

pathstr, optional

path of the data file

xrayutilities.io.panalytical_xml module

Panalytical XML (www.XRDML.com) data file parser

based on the native python xml.dom.minidom module. want to keep the number of dependancies as small as possible

class xrayutilities.io.panalytical_xml.XRDMLFile(fname, path='')[source]

Bases: object

class to handle XRDML data files. The class is supplied with a file name and uses the XRDMLScan class to parse the xrdMeasurement in the file

__init__(fname, path='')[source]

initialization routine supplied with a filename the file is automatically parsed and the data are available in the “scan” object. If more <xrdMeasurement> tags are present, which should not be the case, their data is present in the “scans” object.

Parameters:
fnamestr

filename of the XRDML file

pathstr, optional

path to the XRDML file

class xrayutilities.io.panalytical_xml.XRDMLMeasurement(measurement, namespace='')[source]

Bases: object

class to handle scans in a XRDML datafile

__init__(measurement, namespace='')[source]

initialization routine for a XRDML measurement which parses are all scans within this measurement.

xrayutilities.io.panalytical_xml.getxrdml_map(filetemplate, scannrs=None, path='.', roi=None)[source]

parses multiple XRDML file and concatenates the results for parsing the xrayutilities.io.XRDMLFile class is used. The function can be used for parsing maps measured with the PIXCel 1D detector (and in limited way also for data acquired with a point detector -> see getxrdml_scan instead).

Parameters:
filetemplatestr

template string for the file names, can contain a %d or other replacement variables which are understood be generate_filenames(). also see the scannrs argument which is used to specify the replacement variables.

scannrsint or list, optional

scan number(s)

pathstr, optional

common path to the filenames

roituple, optional

region of interest for the PIXCel detector, for other measurements this is not useful!

Returns:
om, tt, psdndarray

motor positions and data as flattened numpy arrays

Examples

>>> om, tt, psd = xrayutilities.io.getxrdml_map("samplename_%d.xrdml",
... [1, 2], path="data")  
xrayutilities.io.panalytical_xml.getxrdml_scan(filetemplate, *motors, **kwargs)[source]

parses multiple XRDML file and concatenates the results for parsing the xrayutilities.io.XRDMLFile class is used. The function can be used for parsing arbitrary scans and will return the the motor values of the scan motor and additionally the positions of the motors given by in the *motors argument

Parameters:
filetemplatestr

template string for the file names, can contain a %d or other replacement variables which are understood be generate_filenames(). also see the scannrs keyword argument which is used to specify the replacement variables.

motorsstr

motor names to return: e.g.: ‘Omega’, ‘2Theta’, … one can also use abbreviations:

  • ‘Omega’ = ‘om’ = ‘o’

  • ‘2Theta’ = ‘tt’ = ‘t’

  • ‘Chi’ = ‘c’

  • ‘Phi’ = ‘p’

scannrsint or list, optional

scan number(s)

pathstr, optional

common path to the filenames

Returns:
scanmot, mot1, mot2,…, detectorintndarray

motor positions and data as flattened numpy arrays

Examples

>>> scanmot, om, tt, inte = getxrdml_scan(
... "samplename_1.xrdml", 'om', 'tt', path="data")  

xrayutilities.io.pdcif module

class xrayutilities.io.pdcif.pdCIF(filename, datacolumn=None)[source]

Bases: object

the class implements a primitive parser for pdCIF-like files. It reads every entry and collects the information in the header attribute. The first loop containing one of the intensity fields is assumed to be the data the user is interested in and is transfered to the data array which is stored as numpy record array the columns can be accessed by name

intensity fields:

  • _pd_meas_counts_total

  • _pd_meas_intensity_total

  • _pd_proc_intensity_total

  • _pd_proc_intensity_net

  • _pd_calc_intensity_total

  • _pd_calc_intensity_net

alternatively the data column name can be given as argument to the constructor

Parse()[source]

parser of the pdCIF file. the method reads the data from the file and fills the data and header attributes with content

__init__(filename, datacolumn=None)[source]

contructor of the pdCIF class

Parameters:
filenamestr

filename of the file to be parsed

datacolumnstr, optional

name of data column to identify the data loop (default =None; means that a list of default names is used)

class xrayutilities.io.pdcif.pdESG(filename, datacolumn=None)[source]

Bases: pdCIF

class for parsing multiple pdCIF loops in one file. This includes especially *.esg files which are supposed to consist of multiple loops of pdCIF data with equal length.

Upon parsing the class tries to combine the data of these different scans into a single data matrix -> same shape of subscan data is assumed

Parse()[source]

parser of the pdCIF file. the method reads the data from the file and fills the data and header attributes with content

__init__(filename, datacolumn=None)[source]

contructor of the pdCIF class

Parameters:
filenamestr

filename of the file to be parsed

datacolumnstr, optional

name of data column to identify the data loop (default =None; means that a list of default names is used)

xrayutilities.io.pdcif.remove_comments(line, sep='#')[source]

xrayutilities.io.rigaku_ras module

class for reading data + header information from Rigaku RAS (3-column ASCII) files

Such datafiles are generated by the Smartlab Guidance software from Rigaku.

class xrayutilities.io.rigaku_ras.RASFile(filename, path=None)[source]

Bases: object

Represents a RAS data file. The file is read during the constructor call

Parameters:
filenamestr

name of the ras-file

pathstr, optional

path to the data file

Read()[source]

Read the data from the file

__init__(filename, path=None)[source]
class xrayutilities.io.rigaku_ras.RASScan(filename, pos)[source]

Bases: object

Represents a single Scan portion of a RAS data file. The scan is parsed during the constructor call

Parameters:
filenamestr

file name of the data file

posint

seek position of the ‘RAS_HEADER_START’ line

__init__(filename, pos)[source]
xrayutilities.io.rigaku_ras.getras_scan(scanname, scannumbers, *args, **kwargs)[source]

function to obtain the angular cooridinates as well as intensity values saved in RAS datafiles. Especially useful for reciprocal space map measurements, and to combine date from several scans

further more it is possible to obtain even more positions from the data file if more than two string arguments with its names are given

Parameters:
scannamestr or list

name of the scans, for multiple scans this can be a template string or a list of filenames. See generate_filenames() for details and examples.

scannumbersint, tuple or list or None

List of scan numbers or generally replacement values for the template string given as scanname. Set to None if not needed.

argsstr, optional

names of the motors. to read reciprocal space maps measured in coplanar diffraction give:

  • omname: name of the omega motor (or its equivalent)

  • ttname: name of the two theta motor (or its equivalent)

kwargsdict

keyword arguments forwarded to RASFile function

Returns:
[ang1, ang2, …]list

angular positions are extracted from the respective scan header, or motor positions during the scan. this is omitted if no args are given

rasdatandarray

the data values (includes the intensities e.g. rasdata[‘int’]).

Examples

>>> [om, tt], MAP = getras_scan('text%05d.ras', 36, 'Omega',
... 'TwoTheta')  

xrayutilities.io.rotanode_alignment module

parser for the alignment log file of the rotating anode

class xrayutilities.io.rotanode_alignment.RA_Alignment(filename)[source]

Bases: object

class to parse the data file created by the alignment routine (tpalign) at the rotating anode spec installation

this routine does an iterative alignment procedure and saves the center of mass values were it moves after each scan. It iterates between two different peaks and iteratively aligns at each peak between two different motors (om/chi at symmetric peaks, om/phi at asymmetric peaks)

Parse()[source]

parser to read the alignment log and obtain the aligned values at every iteration.

__init__(filename)[source]

initialization function to initialize the objects variables and opens the file

Parameters:
filenamestr

filename of the alignment log file

get(key)[source]
keys()[source]

returns a list of keys for which aligned values were parsed

plot(pname)[source]

function to plot the alignment history for a given peak

Parameters:
pnamestr

peakname for which the alignment should be plotted

xrayutilities.io.seifert module

a set of routines to convert Seifert ASCII files to HDF5 in fact there exist two posibilities how the data is stored (depending on the used detector):

  1. as a simple line scan (using the point detector)

  2. as a map using the PSD

In the first case the data ist stored

class xrayutilities.io.seifert.SeifertHeader[source]

Bases: object

helper class to represent a Seifert (NJA) scan file header

__init__()[source]
class xrayutilities.io.seifert.SeifertMultiScan(filename, m_scan, m2, path='')[source]

Bases: object

Class to parse a Seifert (NJA) multiscan file

__init__(filename, m_scan, m2, path='')[source]

Parse data from a multiscan Seifert file.

Parameters:
filenamestr

name of the NJA file

m_scanstr

name of the scan axis

m2str

name of the second moving motor

pathstr, optional

path to the datafile

parse()[source]
class xrayutilities.io.seifert.SeifertScan(filename, path='')[source]

Bases: object

Class to parse a single Seifert (NJA) scan file

__init__(filename, path='')[source]

Constructor for a SeifertScan object.

Parameters:
filenamestr

a string with the name of the file to read

pathstr, optional

path to the datafile

parse()[source]
xrayutilities.io.seifert.getSeifert_map(filetemplate, scannrs=None, path='.', scantype='map', Nchannels=1280)[source]

parses multiple Seifert *.nja files and concatenates the results. for parsing the xrayutilities.io.SeifertMultiScan class is used. The function can be used for parsing maps measured with the Meteor1D and point detector.

Parameters:
filetemplatestr or list

template string for the file names, or list of filenames. See generate_filenames() for details.

scannrsint or list, optional

scan number(s), or other values needed to generate filenames from the filetemplate.

pathstr, optional

common path to the filenames

scantype{‘map’, ‘O2T’, ‘tsk’}, optional

type of datafile: can be either ‘map’ (reciprocal space map measured with a regular Seifert job (default)) or ‘tsk’ (MCA spectra measured using the TaskInterpreter)

Nchannelsint, optional

number of channels of the MCA (needed for ‘tsk’ measurements)

Returns:
om, tt, psdndarray

positions and data as flattened numpy arrays

Examples

>>> om, tt, psd = getSeifert_map("samplename_%d.xrdml", [1, 2],
... path="data")  
xrayutilities.io.seifert.repair_key(key)[source]

Repair a key string in the sense that the string is changed in a way that it can be used as a valid Python identifier. For that purpose all blanks within the string will be replaced by _ and leading numbers get an preceeding _.

xrayutilities.io.spec module

a class for observing a SPEC data file

Motivation:

SPEC files can become quite large. Therefore, subsequently reading the entire file to extract a single scan is a quite cumbersome procedure. This module is a proof of concept code to write a file observer starting a reread of the file starting from a stored offset (last known scan position)

class xrayutilities.io.spec.SPECCmdLine(n, prompt, cmdl, out='')[source]

Bases: object

__init__(n, prompt, cmdl, out='')[source]
class xrayutilities.io.spec.SPECFile(filename, path='')[source]

Bases: object

This class represents a single SPEC file. The class provides methodes for updateing an already opened file which makes it particular interesting for interactive use.

Parse()[source]

Parses the file from the starting at last_offset and adding found scans to the scan list.

Save2HDF5(h5f, comp=True, optattrs=None)[source]

Save the entire file in an HDF5 file. For that purpose a group is set up in the root group of the file with the name of the file without extension and leading path. If the method is called after an previous update only the scans not written to the file meanwhile are saved.

Parameters:
h5ffile-handle or str

a HDF5 file object or its filename

compbool, optional

activate compression - true by default

Update()[source]

reread the file and add newly added files. The parsing starts at the data offset of the last scan gathered during the last parsing run.

__init__(filename, path='')[source]

SPECFile init routine

Parameters:
filenamestr

filename of the spec file

pathstr, optional

path to the specfile

class xrayutilities.io.spec.SPECLog(filename, prompt, path='')[source]

Bases: object

class to parse a SPEC log file to find the command history

Parse()[source]
__init__(filename, prompt, path='')[source]

init routine for a class to read a SPEC log file

Parameters:
filenamestr

SPEC log file name

promptstr

SPEC command prompt (e.g. ‘PSIC’ or ‘SPEC’)

pathstr, optional

directory where the SPEC log can be found

class xrayutilities.io.spec.SPECScan(name, scannr, command, date, time, itime, colnames, hoffset, doffset, fname, imopnames, imopvalues, scan_status)[source]

Bases: object

Represents a single SPEC scan. This class is usually not called by the user directly but used via the SPECFile class.

ClearData()[source]

Delete the data stored in a scan after it is no longer used.

ReadData()[source]

Set the data attribute of the scan class.

Save2HDF5(h5f, group='/', title='', optattrs=None, comp=True)[source]

Save a SPEC scan to an HDF5 file. The method creates a group with the name of the scan and stores the data there as a table object with name “data”. By default the scan group is created under the root group of the HDF5 file. The title of the scan group is ususally the scan command. Metadata of the scan are stored as attributes to the scan group. Additional custom attributes to the scan group can be passed as a dictionary via the optattrs keyword argument.

Parameters:
h5ffile-handle or str

a HDF5 file object or its filename

groupstr, optional

name or group object of the HDF5 group where to store the data

titlestr, optional

a string with the title for the data, defaults to the name of scan if empty

optattrsdict, optional

a dictionary with optional attributes to store for the data

compbool, optional

activate compression - true by default

SetMCAParams(mca_column_format, mca_channels, mca_start, mca_stop)[source]

Set the parameters used to save the MCA data to the file. This method calculates the number of lines used to store the MCA data from the number of columns and the

Parameters:
mca_column_formatint

number of columns used to save the data

mca_channelsint

number of MCA channels stored

mca_startint

first channel that is stored

mca_stopint

last channel that is stored

__init__(name, scannr, command, date, time, itime, colnames, hoffset, doffset, fname, imopnames, imopvalues, scan_status)[source]

Constructor for the SPECScan class.

Parameters:
namestr

name of the scan

scannrint

Number of the scan in the specfile

commandstr

command used to write the scan

datestr

starting date of the scan

timestr

starting time of the scan

itimeint

integration time

colnameslist

list of names of the data columns

hoffsetint

file byte offset to the header of the scan

doffsetint

file byte offset to the data section of the scan

fnamestr

file name of the SPEC file the scan belongs to

imopnameslist of str

motor names for the initial motor positions array

imopvalueslist

intial motor positions array

scan_status{‘OK’, ‘NODATA’, ‘CORRUPTED’, ‘ABORTED’}

scan status as string

getheader_element(key, firstonly=True)[source]

return the value-string of the first appearance of this SPECScan’s header element, or a list of all values if firstonly=False

Parameters:
specscanSPECScan
keystr

name of the key to return; e.g. ‘UMONO’ or ‘D’

firstonlybool, optional

flag to specify if all instances or only the first one should be returned

Returns:
valuestringstr

header value (if firstonly=True)

[str1, str2, …]list

header values (if firstonly=False)

plot(*args, **keyargs)[source]

Plot scan data to a matplotlib figure. If newfig=True a new figure instance will be created. If logy=True (default is False) the y-axis will be plotted with a logarithmic scale.

Parameters:
argslist

arguments for the plot: first argument is the name of x-value column the following pairs of arguments are the y-value names and plot styles allowed are 3, 5, 7,… number of arguments

keyargsdict, optional
newfigbool, optional

if True a new figure instance will be created otherwise an existing one will be used

logybool, optional

if True a semilogy plot will be done

xrayutilities.io.spec.geth5_scan(h5f, scans, *args, **kwargs)[source]

function to obtain the angular cooridinates as well as intensity values saved in an HDF5 file, which was created from a spec file by the Save2HDF5 method. Especially useful for reciprocal space map measurements.

further more it is possible to obtain even more positions from the data file if more than two string arguments with its names are given

Parameters:
h5ffile-handle or str

file object of a HDF5 file opened using h5py or its filename

scansint, tuple or list

number of the scans of the reciprocal space map

argsstr, optional

names of the motors. to read reciprocal space maps measured in coplanar diffraction give:

  • omname: name of the omega motor (or its equivalent)

  • ttname: name of the two theta motor (or its equivalent)

kwargsdict, optional
samplename: str, optional

string with the hdf5-group containing the scan data if ommited the first child node of h5f.root will be used

rettype: {‘list’, ‘numpy’}, optional

how to return motor positions. by default a list of arrays is returned. when rettype == ‘numpy’ a record array will be returned.

Returns:
[ang1, ang2, …]list

angular positions of the center channel of the position sensitive detector (numpy.ndarray 1D), this list is omitted if no args are given

MAPndarray

the data values as stored in the data file (includes the intensities e.g. MAP[‘MCA’]).

Examples

>>> [om, tt], MAP = geth5_scan("h5file", 36,
... 'omega', 'gamma')  
xrayutilities.io.spec.getspec_scan(specf, scans, *args, **kwargs)[source]

function to obtain the angular cooridinates as well as intensity values saved in a SPECFile. Especially useful to combine the data from multiple scans.

further more it is possible to obtain even more positions from the data file if more than two string arguments with its names are given

Parameters:
specfSPECFile

file object

scansint, tuple or list

number of the scans

argsstr

names of the motors and counters

rettype{‘list’, ‘numpy’}, optional

how to return motor positions. by default a list of arrays is returned. when rettype == ‘numpy’ a record array will be returned.

Returns:
[ang1, ang2, …]list

coordinates and counters from the SPEC file

Examples

>>> [om, tt, cnt2] = getspec_scan(s, 36, 'omega', 'gamma',
... 'Counter2')  

xrayutilities.io.spectra module

module to handle spectra data

class xrayutilities.io.spectra.SPECTRAFile(filename, mcatmp=None, mcastart=None, mcastop=None)[source]

Bases: object

Represents a SPECTRA data file. The file is read during the Constructor call. This class should work for data stored at beamlines P08 and BW2 at HASYLAB.

Parameters:
filenamestr

a string with the name of the SPECTRA file

mcatmpstr, optional

template for the MCA files

mcastart, mcastopint, optional

start and stop index for the MCA files, if not given, the class tries to determine the start and stop index automatically.

Read()[source]

Read the data from the file.

ReadMCA()[source]
Save2HDF5(h5file, name, group='/', mcaname='MCA')[source]

Saves the scan to an HDF5 file. The scan is saved to a seperate group of name “name”. h5file is either a string for the file name or a HDF5 file object. If the mca attribute is not None mca data will be stored to an chunked array of with name mcaname.

Parameters:
h5filefile-handle or str

HDF5 file object or name

namestr

name of the group where to store the data

groupstr, optional

root group where to store the data

mcanamestr, optional

Name of the MCA in the HDF5 file

Returns:
bool or None

The method returns None in the case of everything went fine, True otherwise.

__init__(filename, mcatmp=None, mcastart=None, mcastop=None)[source]
class xrayutilities.io.spectra.SPECTRAFileComments[source]

Bases: dict

Class that describes the comments in the header of a SPECTRA file. The different comments are accessible via the comment keys.

__init__()[source]
class xrayutilities.io.spectra.SPECTRAFileData[source]

Bases: object

__init__()[source]
append(col)[source]
class xrayutilities.io.spectra.SPECTRAFileDataColumn(index, name, unit, type)[source]

Bases: object

__init__(index, name, unit, type)[source]
class xrayutilities.io.spectra.SPECTRAFileParameters[source]

Bases: dict

__init__()[source]
xrayutilities.io.spectra.geth5_spectra_map(h5file, scans, *args, **kwargs)[source]

function to obtain the omega and twotheta as well as intensity values for a reciprocal space map saved in an HDF5 file, which was created from a spectra file by the Save2HDF5 method.

further more it is possible to obtain even more positions from the data file if more than two string arguments with its names are given

Parameters:
h5ffile-handle or str

file object of a HDF5 file opened using h5py

scansint, tuple or list

number of the scans of the reciprocal space map

args: str, optional

arbitrary number of motor names

  • omname: name of the omega motor (or its equivalent)

  • ttname: name of the two theta motor (or its equivalent)

kwargsdict, optional
mcastr, optional

name of the mca data (if available) otherwise None (default: “MCA”)

samplenamestr, optional

string with the hdf5-group containing the scan data if omitted the first child node of h5f.root will be used to determine the sample name

Returns:
[ang1, ang2, …]list

angular positions of the center channel of the position sensitive detector (numpy.ndarray 1D). one entry for every args-argument given to the function

MAPndarray

the data values as stored in the data file (includes the intensities e.g. MAP[‘MCA’]).

Module contents