xrayutilities.io package

Submodules

xrayutilities.io.cbf module

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

Bases: xrayutilities.io.filedir.FileDirectory

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

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:

**h5f ....... a HDF5 file object or name**

**optional keyword arguments:**

group:group where to store the data (default to the root of the file)
comp:activate compression - true by default
xrayutilities.io.cbf.makeNaturalName(name)[source]

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:

**scanname: name of the scans, for multiple scans this needs to be a**

template string

scannumbers:number of the scans of the reciprocal space map (int,tuple or list)

*args: names of the motors (optional) (strings) to read reciprocal space maps measured in coplanar diffraction give: :omname: e.g. name of the omega motor (or its equivalent) :ttname: e.g. name of the two theta motor (or its equivalent)

**keyargs: keyword arguments are passed on to tty08File

Returns:

MAP

or

[ang1,ang2,...],MAP:

angular positions of the center channel of the position sensitive detector (numpy.ndarray 1D) together with 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.

Required constructor arguments:

filename:a string with the name of the tty08-file

Optional keyword arguments:

mcadir:directory name of MCA files
Read()[source]

Read the data from the file

ReadMCA()[source]

xrayutilities.io.edf module

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

Bases: xrayutilities.io.filedir.FileDirectory

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

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:**nimg: 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:

**h5f ...... a HDF5 file object or name**

**optional keyword arguments:**

group:group where to store the data (default to the root of the file)
comp:activate compression - true by default
data
xrayutilities.io.edf.makeNaturalName(name)[source]

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.

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

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

Parameters:

**nx,ny: number of bins in x,y direction**

**optional keyword arguments:**

counter:name of the counter to use for gridding (default: ‘mpx4int’ (ID01))
gridrange:range for the gridder: format: ((xmin,xmax),(ymin,ymax))
Returns:

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:

**motorname: name of the motor for which the position is wanted**

Returns:
val: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(filename, scannr, xmotor='adcX', ymotor='adcY', path='')[source]

Bases: xrayutilities.io.fastscan.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

getccdFileTemplate(specscan, datadir=None, keepdir=0, numfmt='%04d')[source]

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

Parameters:

**specscan: spec-scan object from which header the CCD directory should**

be extracted

datadir: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.
keepdir:number of directories which should be taken from the specscan. (default: 0)
numfmt:format string for the CCD file number (optional)
Returns:
fmtstr:

format string for the CCD file name using one number to

build the real file name

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

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

Parameters:

**nx,ny: number of bins in x,y direction**

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

**optional:**

roi: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)
datadir: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.
keepdir:number of directories which should be taken from the SPEC file. (default: 0)
nav:number of detector pixel which will be averaged together (reduces the date size)
gridrange:range for the gridder: format: ((xmin,xmax),(ymin,ymax))
filterfunc: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,DATA:regular x,y-grid as well as 4-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.

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: list of shifts in x-direction for every FastScan in the**

data structure

deltay:same for the y-direction
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:

**posx: real space x-position or index in x direction**

posy:real space y-position or index in y direction

**optional:**

typ:type of coordinates. specifies if the position is specified as real space coordinate or as index. valid values are ‘real’ and ‘index’. (default: ‘real’)
Returns:

[[motorpos1, ccdnrs1], [motorpos2, ccdnrs2], ...] where motorposN is

from the N-ths FastScan in the series and ccdnrsN is the list of according CCD-frames

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,ny: number of bins in x,y direction**

**optional keyword arguments:**

counter:name of the counter to use for gridding (default: ‘mpx4int’ (ID01))
gridrange: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:

**posx: real space x-position or index in x direction**

posy:real space y-position or index in y direction
qnx:number of points in the Qx direction of the gridded reciprocal space map
qny:same for y direction
qnz:same for z directino
qconv:QConversion-object to be used for the conversion of the CCD-data to reciprocal space

**optional:**

roi: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)
nav:number of detector pixel which will be averaged together (reduces the date size)
typ:type of coordinates. specifies if the position is specified as real space coordinate or as index. valid values are ‘real’ and ‘index’. (default: ‘real’)
filterfunc: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
UB: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, 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:

**posx: real space x-position or index in x direction**

posy:real space y-position or index in y direction
qconv:QConversion-object to be used for the conversion of the CCD-data to reciprocal space

**optional:**

roi: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)
nav:number of detector pixel which will be averaged together (reduces the date size)
typ:type of coordinates. specifies if the position is specified as real space coordinate or as index. valid values are ‘real’ and ‘index’. (default: ‘real’)
filterfunc: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
UB:sample orientation matrix
datadir: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.
keepdir:number of directories which should be taken from the SPEC file. (default: 0)
Returns:
qx,qy,qz,ccddata,valuelist:
 

raw data of the reciprocal space map and

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:

**h5f ..... a HDF5 file object or name**

**optional keyword arguments:**

group:group where to store the data (defaults to pathname if group is empty string)
comp:activate compression - true by default

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

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.

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:

**filename: filename of the file to open (full including path)**

mode:mode in which the file should be opened
Returns:

file handle of the opened file

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.

Required constructor arguments:

filename:a string with the name of the data file
Read()[source]

Read the data from the 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:

**scannumbers: number of the numors, or list of numbers. This will be**

transformed to a string and used as a filename (int, str, or iterable (list, tuple))

*args: names of the motors (optional) (strings)

e.g.: ‘omega’, ‘gamma’

**kwargs: keyword arguments are passed on to numorFile. e.g. ‘path’ for

the files directory

Returns:

data

or

[ang1,ang2,...],data:

angular positions position together with 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.
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:

**filename: 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

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

Bases: xrayutilities.io.imagereader.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.

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

Bases: xrayutilities.io.imagereader.ImageReader

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

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

Bases: xrayutilities.io.imagereader.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.

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

Bases: xrayutilities.io.imagereader.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.

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

read tiff image file and return the data

Parameters:

**filename: filename of the image to be read. so far only single**

filenames are supported. The data might be compressed.

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

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

Bases: object

class to handle scans in a XRDML datafile

xrayutilities.io.panalytical_xml.getOmPixcel(omraw, ttraw)[source]

function to reshape the Omega values into a form needed for further treatment with xrayutilities

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:

**filetemplate: template string for the file names, can contain**

a %d which is replaced by the scan number or be a list of filenames

scannrs:int or list of scan numbers
path:common path to the filenames
roi:region of interest for the PIXCel detector, for other measurements this is not usefull!
Returns:
om,tt,psd: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:

**filetemplate: template string for the file names, can contain**

a %d which is replaced by the scan number or be a list of filenames given by the scannrs keyword argument

*motors: motor names to return: e.g.: ‘Omega’,‘2Theta’,...

one can also use abbreviations ‘Omega’ = ‘om’ = ‘o’ ‘2Theta’ = ‘tt’ = ‘t’ ‘Chi’ = ‘c’ ‘Phi’ = ‘p’

**kwargs:
scannrs:int or list of scan numbers
path:common path to the filenames
Returns:

scanmot,mot1,mot2,...,detectorint: as flattened numpy arrays

Examples

>>> scanmot,om,tt,inte = xrayutilities.io.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

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

Bases: xrayutilities.io.pdcif.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

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

Required constructor arguments:

filename:a string with the name of the ras-file
keyword argument (optional):
path:path to the data file
Read()[source]

Read the data from the file

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

Required constructor arguments:

filename:file name of the data file
pos:seek position of the RAS_HEADER_START line
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:

**scanname: name of the scans, for multiple scans this needs to be a**

template string

scannumbers:number of the scans of the reciprocal space map (int,tuple or list)

*args: names of the motors (optional) (strings) to read reciprocal space maps measured in coplanar diffraction give: :omname: e.g. name of the omega motor (or its equivalent) :ttname: e.g. name of the two theta motor (or its equivalent) **kwargs: keyword arguments forwarded to RASFile function

Returns:

rasdata

or

[ang1,ang2,...],rasdata:

angular positions are extracted from the respective scan header together with all the data values as stored in the data file (includes the intensities e.g. rasdata[‘int’]).

Examples

>>> [om,tt],MAP = xu.io.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.

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:**pname: 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 use 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

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

Bases: object

Class to parse a Seifert (NJA) multiscan file

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

Bases: object

Class to parse a single Seifert (NJA) scan file

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:

**filetemplate: template string for the file names, can contain**

a %d which is replaced by the scan number or be a list of filenames

scannrs:int or list of scan numbers
path:common path to the filenames
scantype: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)
Nchannels:number of channels of the MCA (needed for “tsk” measurements)
Returns:
om,tt,psd:as flattened numpy arrays

Examples

>>> om,tt,psd = xrayutilities.io.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

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={})[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.

required arguments:
h5f:a HDF5 file object or its filename
optional keyword arguments:
comp: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.

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]
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={}, 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.

input arguments:
h5f:a HDF5 file object or its filename
optional keyword arguments:
group:name or group object of the HDF5 group where to store the data
title:a string with the title for the data, defaults to the name of scan if empty
optattrs:a dictionary with optional attributes to store for the data
comp: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

required input aguments:
mca_column_format:
 number of columns used to save the data
mca_channels:number of MCA channels stored
mca_start:first channel that is stored
mca_stop:last channel that is stored
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:

***args: 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

**keyargs:
newfig:if True a new figure instance will be created otherwise an existing one will be used
logy: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:

**h5f: file object of a HDF5 file opened using h5py or its filename**

scans:number of the scans of the reciprocal space map (int,tuple or list)

*args: names of the motors (optional) (strings) to read reciprocal space maps measured in coplanar diffraction give: :omname: e.g. name of the omega motor (or its equivalent) :ttname: e.g. name of the two theta motor (or its equivalent)

**kwargs (optional):
samplename:string with the hdf5-group containing the scan data if ommited the first child node of h5f.root will be used
rettype:how to return motor positions. by default a list of arrays is returned. when rettype == ‘numpy’ a record array will be returned.
Returns:

MAP

or

[ang1,ang2,...],MAP:

angular positions of the center channel of the position sensitive detector (numpy.ndarray 1D) together with all the data values as stored in the data file (includes the intensities e.g. MAP[‘MCA’]).

Examples

>>> [om, tt], MAP = xu.io.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:

**specf: SPECFile object**

scans:number of the scans of the reciprocal space map (int,tuple or list)
args:names of the motors and counters (strings)

**keyword arguments:**

rettype: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,...]:

coordinates and counters from the SPEC file

Examples

>>> [om, tt, cnt2] = xu.io.getspec_scan(s, 36, 'omega', 'gamma',
                                        'Counter2')
xrayutilities.io.spec.makeNaturalName(name)[source]

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.

Required constructor arguments:

filename:a string with the name of the SPECTRA file

Optional keyword arguments:

mcatmp:template for the MCA files
mcastart,mcastop:
 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.

required input arguments:
h5file:string or HDF5 file object
name:name of the group where to store the data
optional keyword arguments:
group:root group where to store the data
mcaname:Name of the MCA in the HDF5 file

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

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.

class xrayutilities.io.spectra.SPECTRAFileData[source]

Bases: object

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

Bases: object

class xrayutilities.io.spectra.SPECTRAFileParameters[source]

Bases: dict

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:

**h5f: file object of a HDF5 file opened using h5py**

scans:number of the scans of the reciprocal space map (int,tuple or list)

***args: arbitrary number of motor names (strings)**

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

****kwargs (optional):**

mca:name of the mca data (if available) otherwise None :(default: “MCA”)
samplename: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,...],MAP:

angular positions of the center channel of the position sensitive detector (numpy.ndarray 1D) together with all the data values as stored in the data file (includes the intensities e.g. MAP[‘MCA’]).

Module contents