srxplanar Package

srxplanar Package

calculate Module

class diffpy.srxplanar.calculate.Calculate(p)

Bases: object

provide methods for integration, variance calculation and distance/Q matrix calculation etc.

calculateIntensity(pic)

calculate the 1D intensity

Parameters:pic – 2D array, array of raw counts, raw counts should be corrected
Retrun :1d array, 1D integrated intensity
calculateVariance(pic)

calculate the 1D intensity

Parameters:pic – 2D array, array of raw counts, raw counts should be corrected
Retrun :1d array, variance of integrated intensity
calculateVarianceLocal(pic)

calculate the variance of raw counts of each pixel are calculated according to their loacl variance.

Parameters:picflat – 1d array, flattend image array
Returns:2d array, variance of each pixel
distance

attribute forwarded to self.config, read-only

genCorrectionMatrix()

generate correction matrix. multiple the 2D raw counts array by this correction matrix to get corrected raw counts. It will calculate solid angle correction or polarization correction.

Returns:2d array, correction matrix to apply on the image
genDistanceMatrix()

Calculate the distance matrix

Returns:2d array, distance between source and each pixel
genIntegrationInds(mask=None)

generate self.bin_number used in integration

Parameters:mask – mask 2D array, same dimension as image, 1 for masked pixel
Returns:self.bin_number
genQMatrix()

Calculate the q matrix

Returns:2d array, q value of each pixel’s center
genTTHMatrix()

Calculate the diffraction angle matrix

Returns:2d array, two theta angle of each pixel’s center
genTTHorQMatrix()

generate a twotheta matrix or q matrix which stores the tth or q value or each pixel

integrationspace

attribute forwarded to self.config, read-only

intensity(pic)

2D to 1D image integration, intensity of pixels are binned and then take average,

Parameters:pic – 2D array, array of raw counts, raw counts should be corrected
Retrun :2d array, [tthorq, intensity, unceratinty] or [tthorq, intensity]
polcorrectf

attribute forwarded to self.config, read-only

polcorrectionenable

attribute forwarded to self.config, read-only

prepareCalculation()

prepare data for calculation

qmax

attribute forwarded to self.config, read-only

qstep

attribute forwarded to self.config, read-only

rotation

attribute forwarded to self.config, read-only

sacorrectionenable

attribute forwarded to self.config, read-only

tilt

attribute forwarded to self.config, read-only

tthmax

attribute forwarded to self.config, read-only

tthmaxd

attribute forwarded to self.config, read-only

tthorqmax

attribute forwarded to self.config, read-only

tthorqstep

attribute forwarded to self.config, read-only

tthstep

attribute forwarded to self.config, read-only

tthstepd

attribute forwarded to self.config, read-only

uncertaintyenable

attribute forwarded to self.config, read-only

wavelength

attribute forwarded to self.config, read-only

xbeamcenter

attribute forwarded to self.config, read-only

xdimension

attribute forwarded to self.config, read-only

xpixelsize

attribute forwarded to self.config, read-only

ybeamcenter

attribute forwarded to self.config, read-only

ydimension

attribute forwarded to self.config, read-only

ypixelsize

attribute forwarded to self.config, read-only

loadimage Module

class diffpy.srxplanar.loadimage.LoadImage(p)

Bases: object

provide methods to filter files and load images

excludepattern

attribute forwarded to self.config, read-only

filenames

attribute forwarded to self.config, read-only

flipImage(pic)

flip image if configured in config

Parameters:pic – 2d array, image array
Returns:2d array, flipped image array
fliphorizontal

attribute forwarded to self.config, read-only

flipvertical

attribute forwarded to self.config, read-only

genFileList(filenames=None, opendir=None, includepattern=None, excludepattern=None)

generate the list of file in opendir according to include/exclude pattern

Parameters:
  • filenames – list of str, list of file name patterns, all files match ANY pattern in this list will be included
  • opendir – str, the directory to get files
  • includepattern – list of str, list of wildcard of files that will be loaded, all files match ALL patterns in this list will be included
  • excludepattern – list of str, list of wildcard of files that will be blocked, any files match ANY patterns in this list will be blocked
Returns:

list of str, a list of filenames (not include their full path)

genFileSet(filenames=None, opendir=None, includepattern=None, excludepattern=None)

generate the list of file in opendir according to include/exclude pattern

Parameters:
  • filenames – list of str, list of file name patterns, all files match ANY pattern in this list will be included
  • opendir – str, the directory to get files
  • includepattern – list of str, list of wildcard of files that will be loaded, all files match ALL patterns in this list will be included
  • excludepattern – list of str, list of wildcard of files that will be blocked, any files match ANY patterns in this list will be blocked
Returns:

set of str, a list of filenames (not include their full path)

includepattern

attribute forwarded to self.config, read-only

loadImage(filename)

load image, then subtract the background if configed in self.backgroundpic.

Parameters:filename – str, image file name
Returns:2d ndarray, 2d image array (flipped)
opendirectory

attribute forwarded to self.config, read-only

xdimension

attribute forwarded to self.config, read-only

ydimension

attribute forwarded to self.config, read-only

mask Module

class diffpy.srxplanar.mask.Mask(p)

Bases: object

provide methods for mask generation, including:

static mask: fit2d (.msk) mask, tif mask, npy mask, masking edge pixels, dymanic mask: masking dead pixels, bright pixels

addmask

attribute forwarded to self.config, read-only

brightPixelMask(pic, size=5, r=1.2)

pixels with much higher intensity compare to adjacent pixels will be masked, this mask is used when there are some bright spots/pixels whose intensity is higher than its neighbors but not too high. Only use this on a very good powder averaged data. Otherwise it may mask wrong pixels.

This mask has similar functions as ‘selfcorr’ function. However, this mask will only consider pixels’ local neighbors pixels and tend to mask more pixels. While ‘selfcorr’ function compare one pixel to other pixels in same bin.

Parameters:
  • pic – 2d array, image array to be processed
  • size – int, size of local area to test if a pixel is a bright pixel
  • r – float, a threshold for masked pixels
Returns:

2d array of boolean, 1 stands for masked pixel

deadPixelMask(pic)

pixels with much lower intensity compare to adjacent pixels will be masked

Parameters:pic – 2d array, image array to be processed
Returns:2d array of boolean, 1 stands for masked pixel
dynamicMask(pic, addmask=None)

create a dynamic mask according to image array. This mask changes for different images

Parameters:
  • pic – 2d array, image array to be processed
  • addmask – list of string, [‘deadpixel’, ‘brightpixel’] deadpixel: pixels with much lower intensity compare to adjacent pixels will be masked brightpixel: pixels with much higher intensity compare to adjacent pixels will be masked
Returns:

2d array of boolean, 1 stands for masked pixel

edgeMask(edges=None)

mask the pixels near edge and around corner

Parameters:edges – list of int (length of 5), first 4 are numbers of pixels masked at each edge in (left, right, top, bottom), last one is the radius of round cut at the corner
Returns:2d array of boolean, 1 stands for masked pixel
flipImage(pic)

flip image if configured in config

Parameters:pic – 2d array, image array
Returns:2d array, flipped image array
fliphorizontal

attribute forwarded to self.config, read-only

flipvertical

attribute forwarded to self.config, read-only

maskedges

attribute forwarded to self.config, read-only

saveMask(filename, pic=None, addmask=None)

generate a mask according to the addmask and pic. save it to .npy. 1 stands for masked pixel the mask has same order as the pic, which means if the pic is flipped, the mask is fliped (when pic is loaded though loadimage, it is flipped)

Parameters:
  • filename – str, filename of mask file to be save
  • pic – 2d array, image array
  • addmask – list of str, control which mask to generate
Returns:

2d array of boolean, 1 stands for masked pixel

staticMask(addmask=None)

create a static mask according existing mask file. This mask remain unchanged for different images

Parameters:addmask – list of string, file name of mask and/or ‘edge’, mask file supported: .msk, .npy, .tif file, ATTN: mask array should be already flipped, and 1 (or larger) stands for masked pixels, 0(<0) stands for unmasked pixels if ‘edge’ is specified here. it will create a mask that mask the pixel near the edge of detector, require self.maskedges
Returns:2d array of boolean, 1 stands for masked pixel
undersample(undersamplerate)

a special mask used for undesampling image. It will create a mask that discard (total number*(1-undersamplerate)) pixels :param undersamplerate: float, 0~1, ratio of pixels to keep

Returns:2d array of boolean, 1 stands for masked pixel
wavelength

attribute forwarded to self.config, read-only

xdimension

attribute forwarded to self.config, read-only

ydimension

attribute forwarded to self.config, read-only

saveresults Module

class diffpy.srxplanar.saveresults.SaveResults(p)

Bases: object

save results into files

filenameplus

attribute forwarded to self.config, read-only

getFilePathWithoutExt(filename)

get the normalized full path of filename with out extension

Parameters:filename – string, could be full path or file name only and with/without ext, only the base part of filename is used.
Returns:string, full normalized path of file without extension
gsasoutput

attribute forwarded to self.config, read-only

integrationspace

attribute forwarded to self.config, read-only

prepareCalculation()
save(rv)

save diffraction intensity in .chi and gsas format(optional)

Parameters:rv – dict, result include integrated diffration intensity the rv[‘chi’] should be a 2d array with shape (2,len of intensity) or (3, len of intensity) file name is generated according to orginal file name and savedirectory
saveChi(xrd, filename)

save diffraction intensity in .chi

Parameters:
  • xrd – 2d array with shape (2,len of intensity) or (3, len of intensity), [tthorq, intensity, (unceratinty)]
  • filename – str, base file name
saveGSAS(xrd, filename)

save diffraction intensity in gsas format

Parameters:
  • xrd – 2d array with shape (2,len of intensity) or (3, len of intensity), [tthorq, intensity, (unceratinty)]
  • filename – str, base file name
savedirectory

attribute forwarded to self.config, read-only

diffpy.srxplanar.saveresults.writeGSASStr(name, mode, tth, iobs, esd=None)

Return string of integrated intensities in GSAS format. :param mode: string, gsas file type, could be ‘std’, ‘esd’, ‘fxye’ (gsas format) :param tth: ndarray, two theta angle :param iobs: ndarray, Xrd intensity :param esd: ndarray, optional error value of intensity

Returns:string, a string to be saved to file

srxplanar Module

srxplanar main modular

class diffpy.srxplanar.srxplanar.SrXplanar(srxplanarconfig=None, configfile=None, args=None, **kwargs)

Bases: object

main modular for srxplanar

createMask(filename=None, pic=None, addmask=None)

create and save a mask according to addmask, pic, 1 stands for masked pixel in saved file

Parameters:
  • filename – name of mask file to save, ‘mask.npy’ if it is None
  • pic – 2d image array, may used in generating dynamic mask, Be careful if this one is flipped or not
  • addmask – list of str, control how to generate mask, see Mask module for detail
Returns:

2d array, 1 stands for masked pixel here

integrate(image, savename=None, savefile=True, flip=True)

integrate 2d image to 1d diffraction pattern, then save to disk

Parameters:
  • image – str or 2d array, if str, then read image file using it as file name. if 2d array, integrate this 2d array.
  • savename – str, name of file to save
  • savefile – boolean, if True, save file to disk, if False, do not save file to disk
  • flip – boolean, if True and ‘image’ is a 2d array, flip this array and integrate it if False and ‘image’ is a 2d array, directly integrate it.
Returns:

dict, rv[‘chi’] is a 2d array of integrated intensity, shape is (2, len of intensity) or (3, len of intensity) in [tth or q, intensity, (uncertainty)]. rv[‘filename’] is the name of file to save to disk

integrateFilelist(filelist, summation=None, filename=None)

process all file in filelist, integrate them separately or together

Parameters:
  • filelist – list of string, file list (full path)
  • summation – bool or None, sum all files together or not, if None, use self.config.summation
  • filename – file name of output file
Returns:

list of dict, in each dict, rv[‘chi’] is a 2d array of integrated intensity, shape is (2, len of intensity) or (3, len of intensity) as [tth or q, intensity, (uncertainty)]. rv[‘filename’] is the name of file to save to disk

prepareCalculation(pic=None)

prepare data used in calculation

Parameters:pic – str, list of str, or 2d array, if provided, then recalculate dynamic mask, using pic
Returns:None
process()

process the images according to filenames/includepattern/excludepattern/summation by default, it will scan current/tifdirectory and integrate all files match includepattern/excludepattern and/or filenames.

Usually this one is called from cmd line rather then script.

Returns:None
updateConfig(filename=None, args=None, **kwargs)

update config using configfile/args/kwargs, then rerun all prepareCalculation()

Parameters:
  • configfile – string, name of config file
  • args – list of str, usually be sys.argv
  • kwargs – you can use like ‘xbeamcenter=1024’ or a dict to update the value of xbeamcenter
Returns:

None

diffpy.srxplanar.srxplanar.main()

read config and integrate images

srxplanarconfig Module

class diffpy.srxplanar.srxplanarconfig.SrXplanarConfig(filename=None, args=None, **kwargs)

Bases: diffpy.confutils.config.ConfigBase

config class, based on ConfigBase class in diffpy.confutils

addmask = ['edgemask']
args = ArgumentParser(prog='sphinx-build', usage=None, description='\nSrXplanar -- integrate 2D powder diffraction image to 1D with unceratinty propagation\n', version=None, formatter_class=<class 'argparse.RawDescriptionHelpFormatter'>, conflict_handler='error', add_help=True)
config = <ConfigParser.ConfigParser instance at 0x2fdd8c0>
configfile = ''
createconfig = ''
createconfigfull = ''
createmask = ''
distance = 200.0
excludepattern = ['*.dark.tif', '*.raw.tif']
filenameplus = ''
filenames = []
fit2dconfig = ''
fliphorizontal = False
flipvertical = True
gsasoutput = 'None'
includepattern = ['*.tif', '*.tif.bz2']
integrationspace = 'twotheta'
maskedges = [20, 20, 20, 20, 100]
nocalculation = False
opendirectory = '/home/xyang/workspace/diffpy/diffpy.srxplanar/doc/manual'
output = ''
polcorrectf = 0.99
polcorrectionenable = True
qstep = 0.02
rotationd = 0.0
sacorrectionenable = True
savedirectory = '/home/xyang/workspace/diffpy/diffpy.srxplanar/doc/manual'
summation = False
tiltd = 0.0
tthstepd = 0.02
uncertaintyenable = True
wavelength = 0.1
xbeamcenter = 1024.0
xdimension = 2048
xpixelsize = 0.2
ybeamcenter = 1024.0
ydimension = 2048
ypixelsize = 0.2
diffpy.srxplanar.srxplanarconfig.checkMax(config)

calculate the max twotheta angle (and q) of a detector with current geometry

Parameters:config – SrXplanarConfig, config instance stores the geometry parameters
Returns:[tthmaxd, qmax], max twotheta angle(in degree) and max q value of current detector.
diffpy.srxplanar.srxplanarconfig.parseFit2D(filename)

load parameters from fit2d calibration information. copy/paste the fit2d calibration results to a txt file. this function will load xbeamcenter, ybeamceter... from the file

Parameters:filename – str, file name (with full path if not in current dir) of fit2d file, or a string containing the calibraiton parameters copy from fit2d.
Returns:dict, including ‘xbeamcenter’, ‘ybeamcenter’, ‘wavelength’, ‘rotationd’(angle of ratation), ‘tiltd’(angle of tilt rotation)

version Module

Definition of __version__, __date__, __gitsha__.

Table Of Contents

Previous topic

confutils Package

This Page