FabIO Package¶
fabio Package¶
fabio.fabioimage Module¶
- Authors: Henning O. Sorensen & Erik Knudsen
Center for Fundamental Research: Metal Structures in Four Dimensions Risoe National Laboratory Frederiksborgvej 399 DK-4000 Roskilde email:erik.knudsen@risoe.dk
and Jon Wright, Jerome Kieffer: ESRF
-
class
fabio.fabioimage.fabioimage(data=None, header=None)¶ Bases:
objectA common object for images in fable Contains a numpy array (.data) and dict of meta data (.header)
-
add(other)¶ Add another Image - warning, does not clip to 16 bit images by default
-
static
checkData(data=None)¶ Empty for fabioimage but may be populated by others classes, especially for format accepting only integers
-
static
checkHeader(header=None)¶ Empty for fabioimage but may be populated by others classes
-
classname¶ Retrieves the name of the class :return: the name of the class
-
convert(dest)¶ Convert a fabioimage object into another fabioimage object (with possible conversions) :param dest: destination type “EDF”, “edfimage” or the class itself
-
getclassname()¶ Retrieves the name of the class :return: the name of the class
-
getframe(num)¶ returns the file numbered ‘num’ in the series as a fabioimage
-
getheader()¶ returns self.header
-
getmax()¶ Find max value in self.data, caching for the future
-
getmean()¶ return the mean
-
getmin()¶ Find min value in self.data, caching for the future
-
getstddev()¶ return the standard deviation
-
integrate_area(coords)¶ Sums up a region of interest if len(coords) == 4 -> convert coords to slices if len(coords) == 2 -> use as slices floor -> ? removed as unused in the function.
-
load(*arg, **kwarg)¶ Wrapper for read
-
make_slice(coords)¶ Convert a len(4) set of coords into a len(2) tuple (pair) of slice objects the latter are immutable, meaning the roi can be cached
-
next()¶ returns the next file in the series as a fabioimage
-
previous()¶ returns the previous file in the series as a fabioimage
-
read(filename, frame=None)¶ To be overridden - fill in self.header and self.data
-
readROI(filename, frame=None, coords=None)¶ Method reading Region of Interest. This implementation is the trivial one, just doing read and crop
-
readheader(filename)¶ Call the _readheader function...
-
rebin(x_rebin_fact, y_rebin_fact, keep_I=True)¶ Rebin the data and adjust dims :param x_rebin_fact: x binning factor :param y_rebin_fact: y binning factor :param keep_I: shall the signal increase ? :type x_rebin_fact: int :type y_rebin_fact: int :type keep_I: boolean
-
resetvals()¶ Reset cache - call on changing data
-
save(fname)¶ wrapper for write
-
toPIL16(filename=None)¶ Convert to Python Imaging Library 16 bit greyscale image
-
update_header(**kwds)¶ update the header entries by default pass in a dict of key, values.
-
write(fname)¶ To be overwritten - write the file
-
-
fabio.fabioimage.test()¶ check some basic fabioimage functionality
fabio.fabioutils Module¶
General purpose utilities functions for fabio
-
class
fabio.fabioutils.BZ2File(name, mode='r', buffering=0, compresslevel=9)¶ Bases:
bz2.BZ2FileWrapper with lock
-
getSize()¶
-
setSize(value)¶
-
size¶
-
-
class
fabio.fabioutils.BytesIO(data, fname=None, mode='r')¶ Bases:
StringIO.StringIOjust an interface providing the name and mode property to a BytesIO
BugFix for MacOSX mainly
-
getSize()¶
-
setSize(size)¶
-
size¶
-
-
class
fabio.fabioutils.DebugSemaphore(*arg, **kwarg)¶ Bases:
threading._Semaphorethreading.Semaphore like class with helper for fighting dead-locks
-
acquire(*arg, **kwarg)¶
-
blocked= []¶
-
release(*arg, **kwarg)¶
-
write_lock= <threading._Semaphore object>¶
-
-
class
fabio.fabioutils.File(name, mode='rb', buffering=0)¶ Bases:
filewrapper for “file” with locking
-
getSize()¶
-
setSize(size)¶
-
size¶
-
-
class
fabio.fabioutils.FilenameObject(stem=None, num=None, directory=None, format=None, extension=None, postnum=None, digits=4, filename=None)¶ Bases:
objectThe ‘meaning’ of a filename ...
-
deconstruct_filename(filename)¶ Break up a filename to get image type and number
-
str()¶ Return a string representation
-
tostring()¶ convert yourself to a string
-
-
class
fabio.fabioutils.GzipFile(filename=None, mode=None, compresslevel=9, fileobj=None)¶ Bases:
gzip.GzipFileJust a wrapper forgzip.GzipFile providing the correct seek capabilities for python 2.5
-
measure_size()¶
-
-
class
fabio.fabioutils.UnknownCompressedFile(name, mode='rb', buffering=0)¶ Bases:
fabio.fabioutils.Filewrapper for “File” with locking
-
fabio.fabioutils.construct_filename(filename, frame=None)¶ Try to construct the filename for a given frame
-
fabio.fabioutils.deconstruct_filename(filename)¶ Function for backward compatibility. Deprecated
-
fabio.fabioutils.deprecated(func)¶ used to deprecate a function/method: prints a lot of warning messages to enforce the modifaction of the code
-
fabio.fabioutils.extract_filenumber(name)¶ extract file number
-
fabio.fabioutils.getnum(name)¶ # try to figure out a file number # guess it starts at the back
-
fabio.fabioutils.isAscii(name, listExcluded=None)¶ Parameters: - name – string to check
- listExcluded – list of char or string excluded.
Returns: True of False whether name is pure ascii or not
-
fabio.fabioutils.jump_filename(name, num, padding=True)¶ jump to number
-
fabio.fabioutils.next_filename(name, padding=True)¶ increment number
-
fabio.fabioutils.nice_int(s)¶ Workaround that int(‘1.0’) raises an exception
Parameters: s – string to be converted to integer
-
fabio.fabioutils.numstem(name)¶ cant see how to do without reversing strings Match 1 or more digits going backwards from the end of the string
-
fabio.fabioutils.pad(mystr, pattern=' ', size=80)¶ Performs the padding of the string to the right size with the right pattern
-
fabio.fabioutils.previous_filename(name, padding=True)¶ decrement number
-
fabio.fabioutils.toAscii(name, excluded=None)¶ Parameters: - name – string to check
- excluded – tuple of char or string excluded (not list: they are mutable).
Returns: the name with all non valid char removed
-
fabio.fabioutils.to_str(s)¶
fabio.file_series Module¶
fabio.openimage Module¶
- Authors: Henning O. Sorensen & Erik Knudsen
- Center for Fundamental Research: Metal Structures in Four Dimensions Risoe National Laboratory Frederiksborgvej 399 DK-4000 Roskilde email:henning.sorensen@risoe.dk
mods for fabio by JPW modification for HDF5 by Jérôme Kieffer
-
fabio.openimage.do_magic(byts)¶ Try to interpret the bytes starting the file as a magic number
-
fabio.openimage.openheader(filename)¶ return only the header
-
fabio.openimage.openimage(filename, frame=None)¶ Try to open an image
fabio.adscimage Module¶
- Authors: Henning O. Sorensen & Erik Knudsen
- Center for Fundamental Research: Metal Structures in Four Dimensions Risoe National Laboratory Frederiksborgvej 399 DK-4000 Roskilde email:erik.knudsen@risoe.dk
- mods for fabio by JPW
-
class
fabio.adscimage.adscimage(*args, **kwargs)¶ Bases:
fabio.fabioimage.fabioimageRead an image in ADSC format (quite similar to edf?)
-
read(fname, frame=None)¶ read in the file
-
swap_needed()¶
-
write(fname)¶ Write adsc format
-
-
fabio.adscimage.test()¶ testcase
fabio.binaryimage Module¶
Authors: Gael Goret, Jerome Kieffer, ESRF, France
- Emails: gael.goret@esrf.fr, jerome.kieffer@esrf.fr
- Brian Richard Pauw <brian@stack.nl>
Binary files images are simple none-compressed 2D images only defined by their : data-type, dimensions, byte order and offset
This simple library has been made for manipulating exotic/unknown files format.
-
class
fabio.binaryimage.binaryimage(*args, **kwargs)¶ Bases:
fabio.fabioimage.fabioimageThis simple library has been made for manipulating exotic/unknown files format.
- Binary files images are simple none-compressed 2D images only defined by their:
- data-type, dimensions, byte order and offset
if offset is set to a negative value, the image is read using the last data but n data in the file, skipping any header.
-
estimate_offset_value(fname, dim1, dim2, bytecode='int32')¶ Estimates the size of a file
-
read(fname, dim1, dim2, offset=0, bytecode='int32', endian='<')¶ Read a binary image
Parameters: - fname (string) – file name
- dim1 – image dimensions (Fast index)
- dim2 – image dimensions (Slow index)
- offset – starting position of the data-block. If negative, starts at the end.
- bytecode – can be “int8”,”int16”,”int32”,”int64”,”uint8”,”uint16”,”uint32”,”uint64”,”float32”,”float64”,...
- endian – among short or long endian (“<” or “>”)
-
static
swap_needed(endian)¶ Decide if we need to byteswap
-
write(fname)¶
fabio.bruker100image Module¶
- Authors: Henning O. Sorensen & Erik Knudsen
Center for Fundamental Research: Metal Structures in Four Dimensions Risoe National Laboratory Frederiksborgvej 399 DK-4000 Roskilde email:erik.knudsen@risoe.dk
Jérôme Kieffer, ESRF, Grenoble, France
-
class
fabio.bruker100image.bruker100image(data=None, header=None)¶ Bases:
fabio.brukerimage.brukerimage-
read(fname, frame=None)¶
-
toPIL16(filename=None)¶
-
write(fname)¶
-
fabio.brukerimage Module¶
- Authors: Henning O. Sorensen & Erik Knudsen
- Center for Fundamental Research: Metal Structures in Four Dimensions Risoe National Laboratory Frederiksborgvej 399 DK-4000 Roskilde email:erik.knudsen@risoe.dk
- Based on: openbruker,readbruker, readbrukerheader functions in the opendata
- module of ImageD11 written by Jon Wright, ESRF, Grenoble, France
Writer by Jérôme Kieffer, ESRF, Grenoble, France
-
class
fabio.brukerimage.brukerimage(data=None, header=None)¶ Bases:
fabio.fabioimage.fabioimageRead and eventually write ID11 bruker (eg smart6500) images
TODO: int32 -> float32 conversion according to the “linear” keyword. This is done and works but we need to check with other program that we are appliing the right formula and not the reciprocal one.
-
HEADERS_KEYS= ['FORMAT', 'VERSION', 'HDRBLKS', 'TYPE', 'SITE', 'MODEL', 'USER', 'SAMPLE', 'SETNAME', 'RUN', 'SAMPNUM', 'TITLE', 'NCOUNTS', 'NOVERFL', 'MINIMUM', 'MAXIMUM', 'NONTIME', 'NLATE', 'FILENAM', 'CREATED', 'CUMULAT', 'ELAPSDR', 'ELAPSDA', 'OSCILLA', 'NSTEPS', 'RANGE', 'START', 'INCREME', 'NUMBER', 'NFRAMES', 'ANGLES', 'NOVER64', 'NPIXELB', 'NROWS', 'NCOLS', 'WORDORD', 'LONGORD', 'TARGET', 'SOURCEK', 'SOURCEM', 'FILTER', 'CELL', 'MATRIX', 'LOWTEMP', 'TEMP', 'HITEMP', 'ZOOM', 'CENTER', 'DISTANC', 'TRAILER', 'COMPRES', 'LINEAR', 'PHD', 'PREAMP', 'CORRECT', 'WARPFIL', 'WAVELEN', 'MAXXY', 'AXIS', 'ENDING', 'DETPAR', 'LUT', 'DISPLIM', 'PROGRAM', 'ROTATE', 'BITMASK', 'OCTMASK', 'ESDCELL', 'DETTYPE', 'NEXP', 'CCDPARM', 'BIS', 'CHEM', 'MORPH', 'CCOLOR', 'CSIZE', 'DNSMET', 'DARK', 'AUTORNG', 'ZEROADJ', 'XTRANS', 'HKL&XY', 'AXES2', 'ENDING2', 'FILTER2', 'LEPTOS', 'CFR']¶
-
SPACER= '\x1a\x04'¶
-
basic_translate(fname=None)¶ Does some basic population of the headers so that the writing is possible
-
bpp_to_numpy= {1: <type 'numpy.uint8'>, 2: <type 'numpy.uint16'>, 4: <type 'numpy.uint32'>}¶
-
calc_bpp(data=None, max_entry=4096)¶ Calculate the number of byte per pixel to get an optimal overflow table.
Returns: byte per pixel
-
gen_header()¶ Generate headers (with some magic and guesses) :param format can be 86 or 100
-
gen_overflow()¶ Generate an overflow table
-
read(fname, frame=None)¶ Read in and unpack the pixels (including overflow table
-
write(fname)¶ Write a bruker image
-
-
fabio.brukerimage.test()¶ a testcase
fabio.cbfimage Module¶
- Authors: Jérôme Kieffer, ESRF
- email:jerome.kieffer@esrf.fr
Cif Binary Files images are 2D images written by the Pilatus detector and others. They use a modified (simplified) byte-offset algorithm.
CIF is a library for manipulating Crystallographic information files and tries to conform to the specification of the IUCR
-
class
fabio.cbfimage.CIF(_strFilename=None)¶ Bases:
dictThis is the CIF class, it represents the CIF dictionary; and as a a python dictionary thus inherits from the dict built in class.
keys are always unicode (str in python3) values are bytes
-
BINARY_MARKER= '--CIF-BINARY-FORMAT-SECTION--'¶
-
BLANK= [' ', '\t', '\r', '\n', '\r\n', '\n\r']¶
-
DATA= 'data_'¶
-
DOUBLE_QUOTE= '"'¶
-
EOL= ['\r', '\n', '\r\n', '\n\r']¶
-
GLOBAL= 'global_'¶
-
HASH= '#'¶
-
LOOP= 'loop_'¶
-
static
LoopHasKey(loop, key)¶ Returns True if the key (string) exist in the array called loop
-
QUESTIONMARK= '?'¶
-
SAVE= 'save_'¶
-
SEMICOLUMN= ';'¶
-
SINGLE_QUOTE= "'"¶
-
START_COMMENT= ("'", '"')¶
-
STOP= 'stop_'¶
-
UNDERSCORE= '_'¶
-
exists(sKey)¶ Check if the key exists in the CIF and is non empty. :param sKey: CIF key :type sKey: string :param cif: CIF dictionary :return: True if the key exists in the CIF dictionary and is non empty :rtype: boolean
-
existsInLoop(sKey)¶ Check if the key exists in the CIF dictionary. :param sKey: CIF key :type sKey: string :param cif: CIF dictionary :return: True if the key exists in the CIF dictionary and is non empty :rtype: boolean
-
i= '\t'¶
-
static
isAscii(text)¶ Check if all characters in a string are ascii,
Parameters: _strIn (python string) – input string Returns: boolean Return type: boolean
-
loadCHIPLOT(_strFilename)¶ Load the powder diffraction CHIPLOT file and returns the pd_CIF dictionary in the object
Parameters: _strFilename (string) – the name of the file to open Returns: the CIF object corresponding to the powder diffraction Return type: dictionary
-
loadCIF(_strFilename, _bKeepComment=False)¶ Load the CIF file and populates the CIF dictionary into the object :param _strFilename: the name of the file to open :type _strFilename: string :param _strFilename: the name of the file to open :type _strFilename: string :return: None
-
pop(key, default=None)¶
-
popitem(key, default=None)¶
-
readCIF(_strFilename, _bKeepComment=False)¶ Load the CIF file and populates the CIF dictionary into the object :param _strFilename: the name of the file to open :type _strFilename: string :param _strFilename: the name of the file to open :type _strFilename: string :return: None
-
saveCIF(_strFilename='test.cif', linesep='\n', binary=False)¶ Transforms the CIF object in string then write it into the given file :param _strFilename: the of the file to be written :param linesep: line separation used (to force compatibility with windows/unix) :param binary: Shall we write the data as binary (True only for imageCIF/CBF) :return: None
-
tostring(_strFilename=None, linesep='\n')¶ Converts a cif dictionnary to a string according to the CIF syntax
param _strFilename: the name of the filename to be appended in the header of the CIF file type _strFilename: string param linesep: default line separation: can be “ ” or ” “
return: a string that corresponds to the content of the CIF-file.
-
-
class
fabio.cbfimage.cbfimage(data=None, header=None, fname=None)¶ Bases:
fabio.fabioimage.fabioimageRead the Cif Binary File data format
-
static
checkData(data=None)¶
-
read(fname, frame=None)¶ - Read in header into self.header and
- the data into self.data
-
write(fname)¶ write the file in CBF format :param fname: name of the file :type: string
-
static
fabio.dm3image Module¶
- Authors: Henning O. Sorensen & Erik Knudsen
- Center for Fundamental Research: Metal Structures in Four Dimensions Risoe National Laboratory Frederiksborgvej 399 DK-4000 Roskilde email:erik.knudsen@risoe.dk
- Jon Wright, ESRF
fabio.edfimage Module¶
License: GPLv2+
Authors:¶
- Henning O. Sorensen & Erik Knudsen: Center for Fundamental Research: Metal Structures in Four Dimensions; Risoe National Laboratory; Frederiksborgvej 399; DK-4000 Roskilde; email:erik.knudsen@risoe.dk
- Jon Wright & Jérôme Kieffer: European Synchrotron Radiation Facility; Grenoble (France)
-
class
fabio.edfimage.Frame(data=None, header=None, header_keys=None, number=None)¶ Bases:
objectA class representing a single frame in an EDF file
-
bytecode¶
-
data¶ Unpack a binary blob according to the specification given in the header
Returns: dataset as numpy.ndarray
-
getByteCode()¶
-
getData()¶ Unpack a binary blob according to the specification given in the header
Returns: dataset as numpy.ndarray
-
getEdfBlock(force_type=None, fit2dMode=False)¶ Parameters: - force_type (string or numpy.dtype) – type of the dataset to be enforced like “float64” or “uint16”
- fit2dMode (boolean) – enforce compatibility with fit2d and starts counting number of images at 1
Returns: ascii header block + binary data block
Return type: python bytes with the concatenation of the ascii header and the binary data block
-
parseheader(block)¶ Parse the header in some EDF format from an already open file
Parameters: block (string, should be full ascii) – string representing the header block. Returns: size of the binary blob
-
setByteCode(_iVal)¶
-
setData(npa=None)¶ Setter for data in edf frame
-
swap_needed()¶ Decide if we need to byteswap
-
-
class
fabio.edfimage.edfimage(data=None, header=None, header_keys=None, frames=None)¶ Bases:
fabio.fabioimage.fabioimageRead and try to write the ESRF edf data format
-
appendFrame(frame=None, data=None, header=None)¶ Method used add a frame to an EDF file :param frame: frame to append to edf image :type frame: instance of Frame :return: None
-
bpp¶
-
bytecode¶
-
capsHeader¶ property: capsHeader of EDF file, i.e. the keys of the header in UPPER case.
-
static
checkHeader(header=None)¶ Empty for fabioimage but may be populated by others classes
-
data¶ property: data of EDF file
-
delCapsHeader()¶ deleter for edf capsHeader
-
delData()¶ deleter for edf Data
-
delHeader()¶ Deleter for edf header
-
delHeaderKeys()¶ Deleter for edf header_keys
-
deleteFrame(frameNb=None)¶ Method used to remove a frame from an EDF image. by default the last one is removed. :param frameNb: frame number to remove, by default the last. :type frameNb: integer :return: None
-
dim1¶
-
dim2¶
-
dims¶
-
fastReadData(filename=None)¶ This is a special method that will read and return the data from another file ... The aim is performances, ... but only supports uncompressed files.
Returns: data from another file using positions from current edfimage
-
fastReadROI(filename, coords=None)¶ Method reading Region of Interest of another file based on metadata available in current edfimage. The aim is performances, ... but only supports uncompressed files.
Returns: ROI-data from another file using positions from current edfimage Return type: numpy 2darray
-
getBpp()¶
-
getByteCode()¶
-
getCapsHeader()¶ getter for edf headers keys in upper case :return: data for current frame :rtype: dict
-
getData()¶ getter for edf Data :return: data for current frame :rtype: numpy.ndarray
-
getDim1()¶
-
getDim2()¶
-
getDims()¶
-
getHeader()¶ Getter for the headers. used by the property header,
-
getHeaderKeys()¶ Getter for edf header_keys
-
getNbFrames()¶ Getter for number of frames
-
getframe(num)¶ returns the file numbered ‘num’ in the series as a fabioimage
-
header¶ property: header of EDF file
-
header_keys¶ property: header_keys of EDF file
-
next()¶ returns the next file in the series as a fabioimage
-
nframes¶ Getter for number of frames
-
previous()¶ returns the previous file in the series as a fabioimage
-
read(fname, frame=None)¶ - Read in header into self.header and
- the data into self.data
-
setBpp(_iVal)¶
-
setByteCode(_iVal)¶
-
setCapsHeader(_data)¶ Enforces the propagation of the header_keys to the list of frames :param _data: numpy array representing data
-
setData(_data)¶ Enforces the propagation of the data to the list of frames :param _data: numpy array representing data
-
setDim1(_iVal)¶
-
setDim2(_iVal)¶
-
setHeader(_dictHeader)¶ Enforces the propagation of the header to the list of frames
-
setHeaderKeys(_listtHeader)¶ Enforces the propagation of the header_keys to the list of frames :param _listtHeader: list of the (ordered) keys in the header :type _listtHeader: python list
-
setNbFrames(val)¶ Setter for number of frames ... should do nothing. Here just to avoid bugs
-
swap_needed()¶ Decide if we need to byteswap
:return True if needed, False else and None if not understood
-
unpack()¶ Unpack a binary blob according to the specification given in the header and return the dataset
Returns: dataset as numpy.ndarray
-
write(fname, force_type=None, fit2dMode=False)¶ Try to write a file check we can write zipped also mimics that fabian was writing uint16 (we sometimes want floats)
Parameters: force_type – can be numpy.uint16 or simply “float” Returns: None
-
fabio.fit2dmaskimage Module¶
Author: Andy Hammersley, ESRF Translation into python/fabio: Jon Wright, ESRF. Writer: Jérôme Kieffer
-
class
fabio.fit2dmaskimage.fit2dmaskimage(data=None, header=None)¶ Bases:
fabio.fabioimage.fabioimageRead and try to write Andy Hammersley’s mask format
-
static
checkData(data=None)¶
-
read(fname, frame=None)¶ - Read in header into self.header and
- the data into self.data
-
write(fname)¶ Try to write a file
-
static
fabio.fit2dspreadsheetimage Module¶
- Read the fit2d ascii image output
- Jon Wright, ESRF
-
class
fabio.fit2dspreadsheetimage.fit2dspreadsheetimage(data=None, header=None)¶ Bases:
fabio.fabioimage.fabioimageRead a fit2d ascii format
-
read(fname, frame=None)¶ - Read in header into self.header and
- the data into self.data
-
fabio.GEimage Module¶
-
class
fabio.GEimage.GEimage(data=None, header=None)¶ Bases:
fabio.fabioimage.fabioimage-
getframe(num)¶ Returns a frame as a new fabioimage object
-
next()¶ Get the next image in a series as a fabio image
-
previous()¶ Get the previous image in a series as a fabio image
-
read(fname, frame=None)¶ Read in header into self.header and the data into self.data
-
write(fname, force_type=<type 'numpy.uint16'>)¶ Not yet implemented
-
-
fabio.GEimage.demo()¶
fabio.hdf5mage Module¶
HDF5 image for FabIO
Authors: Jerome Kieffer email: Jerome.Kieffer@terre-adelie.org
Specifications: input should being the form:
hdf5:///filename?path#slice=[:,:,1]
-
class
fabio.hdf5image.hdf5image(*arg, **kwargs)¶ Bases:
fabio.fabioimage.fabioimageFabIO image class for Images from an HDF file
-
get_slice()¶
-
getframe(num)¶ Returns a frame as a new fabioimage object :param num: frame number
-
next()¶ Get the next image in a series as a fabio image
-
previous()¶ Get the previous image in a series as a fabio image
-
read(fname, frame=None)¶ try to read image :param fname: name of the file as hdf5:///filename?path#slice=[:,:,1]
-
set_url(url)¶ set the url of the data
-
write(fname, force_type=<type 'numpy.uint16'>)¶
-
fabio.HiPiCimage Module¶
- Authors: Henning O. Sorensen & Erik Knudsen
- Center for Fundamental Research: Metal Structures in Four Dimensions Risoe National Laboratory Frederiksborgvej 399 DK-4000 Roskilde email:erik.knudsen@risoe.dk
- Jon Wright, ESRF
Information about the file format from Masakatzu Kobayashi is highly appreciated
-
class
fabio.HiPiCimage.HiPiCimage(data=None, header=None)¶ Bases:
fabio.fabioimage.fabioimageRead HiPic images e.g. collected with a Hamamatsu CCD camera
-
read(fname, frame=None)¶ - Read in header into self.header and
- the data into self.data
-
fabio.kcdimage Module¶
- Authors: Jerome Kieffer, ESRF
- email:jerome.kieffer@esrf.fr
kcd images are 2D images written by the old KappaCCD diffractometer built by Nonius in the 1990’s Based on the edfimage.py parser.
-
class
fabio.kcdimage.kcdimage(data=None, header=None)¶ Bases:
fabio.fabioimage.fabioimageRead the Nonius kcd data format
-
static
checkData(data=None)¶
-
read(fname, frame=None)¶ - Read in header into self.header and
- the data into self.data
-
static
fabio.mar345image Module¶
Authors:¶
- Henning O. Sorensen & Erik Knudsen: Center for Fundamental Research: Metal Structures in Four Dimensions; Risoe National Laboratory; Frederiksborgvej 399; DK-4000 Roskilde; email:erik.knudsen@risoe.dk
- Jon Wright, Jérôme Kieffer & Gaël Goret: European Synchrotron Radiation Facility; Grenoble (France)
Supports Mar345 imaging plate and Mar555 flat panel
Documentation on the format is available from: http://rayonix.com/site_media/downloads/mar345_formats.pdf
-
class
fabio.mar345image.mar345image(*args, **kwargs)¶ Bases:
fabio.fabioimage.fabioimage-
ascii_header(linesep='\n', size=4096)¶ Generate the ASCII header for writing
Parameters: - linesep – end of line separator
- size – size of the header (without the binary header)
Returns: string (unicode) containing the mar345 header
-
binary_header()¶ Returns: Binary header of mar345 file
-
static
checkData(data=None)¶
-
nb_overflow_pixels()¶
-
read(fname, frame=None)¶ Read a mar345 image
-
write(fname)¶ Try to write mar345 file. This is still in beta version. It uses CCP4 (LGPL) PCK1 algo from JPA
-
fabio.mrcimage Module¶
fabio.marccdimage Module¶
Authors:¶
- Henning O. Sorensen & Erik Knudsen: Center for Fundamental Research: Metal Structures in Four Dimensions; Risoe National Laboratory; Frederiksborgvej 399; DK-4000 Roskilde; email:erik.knudsen@risoe.dk
- Jon Wright: European Synchrotron Radiation Facility; Grenoble (France)
marccdimage can read MarCCD and MarMosaic images including header info.
JPW : Use a parser in case of typos (sorry?)
-
fabio.marccdimage.interpret_header(header, fmt, names)¶ given a format and header interpret it
-
fabio.marccdimage.make_format(c_def_string)¶ Reads the header definition in c and makes the format string to pass to struct.unpack
-
class
fabio.marccdimage.marccdimage(*args, **kwds)¶ Bases:
fabio.tifimage.tifimageRead in data in mar ccd format, also MarMosaic images, including header info
fabio.OXDimage Module¶
Reads Oxford Diffraction Sapphire 3 images
Authors:¶
- Henning O. Sorensen & Erik Knudsen: Center for Fundamental Research: Metal Structures in Four Dimensions; Risoe National Laboratory; Frederiksborgvej 399; DK-4000 Roskilde; email:erik.knudsen@risoe.dk
- Jon Wright, Jérôme Kieffer & Gaël Goret: European Synchrotron Radiation Facility; Grenoble (France)
-
class
fabio.OXDimage.OXDimage(data=None, header=None)¶ Bases:
fabio.fabioimage.fabioimageOxford Diffraction Sapphire 3 images reader/writer class
Note: We assume the binary format is alway little-endian, is this True ?
-
static
checkData(data=None)¶
-
getCompressionRatio()¶ calculate the compression factor obtained vs raw data
-
read(fname, frame=None)¶ - Read in header into self.header and
- the data into self.data
-
write(fname)¶ Write Oxford diffraction images: this is still beta Only TY1 compressed images is currently possible :param fname: output filename
-
static
-
class
fabio.OXDimage.Section(size, dictHeader)¶ Bases:
objectSmall helper class for writing binary headers
-
getSize(dtype)¶
-
setData(key, offset, dtype, default=None)¶ Parameters: - offset – int, starting position in the section
- key – name of the header key
- dtype – type of the data to insert (defines the size!)
-
fabio.pilatusimage Module¶
Authors:¶
- Henning O. Sorensen & Erik Knudsen: Center for Fundamental Research: Metal Structures in Four Dimensions; Risoe National Laboratory; Frederiksborgvej 399; DK-4000 Roskilde; email:erik.knudsen@risoe.dk
- Jon Wright: European Synchrotron Radiation Facility; Grenoble (France)
-
class
fabio.pilatusimage.pilatusimage(*args, **kwds)¶ Bases:
fabio.tifimage.tifimageRead in Pilatus format, also pilatus images, including header info
fabio.pixiimage Module¶
Author: Jon Wright, ESRF.
-
fabio.pixiimage.demo(fname)¶
-
class
fabio.pixiimage.pixiimage(data=None, header=None)¶ Bases:
fabio.fabioimage.fabioimage-
getframe(num)¶ Returns a frame as a new fabioimage object
-
next()¶ Get the next image in a series as a fabio image
-
previous()¶ Get the previous image in a series as a fabio image
-
read(fname, frame=None)¶
-
write(fname, force_type=<type 'numpy.uint16'>)¶
-
fabio.pnmimage Module¶
- Authors: Henning O. Sorensen & Erik Knudsen
- Center for Fundamental Research: Metal Structures in Four Dimensions Risoe National Laboratory Frederiksborgvej 399 DK-4000 Roskilde email:henning.sorensen@risoe.dk
- Jérôme Kieffer: European Synchrotron Radiation Facility; Grenoble (France)
License: GPLv3+
-
class
fabio.pnmimage.pnmimage(*arg, **kwargs)¶ Bases:
fabio.fabioimage.fabioimage-
P1dec(buf, bytecode)¶
-
P2dec(buf, bytecode)¶
-
P3dec(buf, bytecode)¶
-
P4dec(buf, bytecode)¶
-
P5dec(buf, bytecode)¶
-
P6dec(buf, bytecode)¶
-
P7dec(buf, bytecode)¶
-
static
checkData(data=None)¶
-
read(fname, frame=None)¶ try to read PNM images :param fname: name of the file :param frame: not relevant here! PNM is always single framed
-
write(filename)¶
-
fabio.raxisimage Module¶
Authors: Brian R. Pauw email: brian@stack.nl
Written using information gleaned from the ReadRAXISImage program written by T. L. Hendrixson, made available by Rigaku Americas. Available at: http://www.rigaku.com/downloads/software/readimage.html
-
class
fabio.raxisimage.raxisimage(*arg, **kwargs)¶ Bases:
fabio.fabioimage.fabioimageFabIO image class to read Rigaku RAXIS image files. Write functions are not planned as there are plenty of more suitable file formats available for storing detector data. In particular, the MSB used in Rigaku files is used in an uncommon way: it is used as a multiply-by flag rather than a normal image value bit. While it is said to multiply by the value specified in the header, there is at least one case where this is found not to hold, so YMMV and be careful.
-
read(fname, frame=None)¶ try to read image :param fname: name of the file :param frame:
-
rigakuKeys()¶
-
swap_needed()¶ not sure if this function is needed
-
fabio.tifimage Module¶
FabIO class for dealing with TIFF images. In facts wraps TiffIO from V. Armando Solé (available in PyMca) or falls back to PIL
Authors:¶
- Henning O. Sorensen & Erik Knudsen: Center for Fundamental Research: Metal Structures in Four Dimensions; Risoe National Laboratory; Frederiksborgvej 399; DK-4000 Roskilde; email:erik.knudsen@risoe.dk
- Jérôme Kieffer: European Synchrotron Radiation Facility; Grenoble (France)
License: GPLv3+
-
class
fabio.tifimage.Image_File_Directory(instring=None, offset=-1)¶ Bases:
object-
unpack(instring, offset=-1)¶
-
-
class
fabio.tifimage.Image_File_Directory_entry(tag=0, tag_type=0, count=0, offset=0)¶ Bases:
object-
extract_data(full_string)¶
-
unpack(strInput)¶
-
-
class
fabio.tifimage.Tiff_header(string)¶ Bases:
object
-
class
fabio.tifimage.tifimage(*args, **kwds)¶ Bases:
fabio.fabioimage.fabioimageImages in TIF format Wraps TiffIO
-
read(fname, frame=None)¶ Wrapper for TiffIO.
-
write(fname)¶ Overrides the fabioimage.write method and provides a simple TIFF image writer. :param fname: name of the file to save the image to @tag_type fname: string or unicode (file?)...
-
fabio.xsdimage Module¶
- Authors: Jérôme Kieffer, ESRF
- email:jerome.kieffer@esrf.fr
XSDimge are XML files containing numpy arrays
-
class
fabio.xsdimage.xsdimage(data=None, header=None, fname=None)¶ Bases:
fabio.fabioimage.fabioimageRead the XSDataImage XML File data format
-
read(fname, frame=None)¶
-
fabio.compression Module¶
- Authors: Jérôme Kieffer, ESRF
- email:jerome.kieffer@esrf.fr
FabIO library containing compression and decompression algorithm for various
-
fabio.compression.compByteOffset(data)¶ Compress a dataset into a string using the byte_offet algorithm
Parameters: data – ndarray Returns: string/bytes with compressed data test = numpy.array([0,1,2,127,0,1,2,128,0,1,2,32767,0,1,2,32768,0,1,2,2147483647,0,1,2,2147483648,0,1,2,128,129,130,32767,32768,128,129,130,32768,2147483647,2147483648])
-
fabio.compression.compByteOffset_numpy(data)¶ Compress a dataset into a string using the byte_offet algorithm
Parameters: data – ndarray Returns: string/bytes with compressed data test = numpy.array([0,1,2,127,0,1,2,128,0,1,2,32767,0,1,2,32768,0,1,2,2147483647,0,1,2,2147483648,0,1,2,128,129,130,32767,32768,128,129,130,32768,2147483647,2147483648])
-
fabio.compression.compPCK(data)¶ Modified CCP4 pck compressor used in MAR345 images
Parameters: data – numpy.ndarray (square array) Returns: compressed stream
-
fabio.compression.compTY1(data)¶ Modified byte offset compressor used in Oxford Diffraction images
Parameters: data – numpy.ndarray with the input data (integers!) Returns: 3-tuple of strings: raw_8,raw_16,raw_32 containing raw data with integer of the given size
-
fabio.compression.decByteOffset(stream, size=None)¶ - Analyze a stream of char with any length of exception:
- 2, 4, or 8 bytes integers
Parameters: - stream – string representing the compressed data
- size – the size of the output array (of longInts)
Returns: 1D-ndarray
-
fabio.compression.decByteOffset_cython(stream, size=None)¶ - Analyze a stream of char with any length of exception:
- 2, 4, or 8 bytes integers
Parameters: - stream – string representing the compressed data
- size – the size of the output array (of longInts)
Returns: 1D-ndarray
-
fabio.compression.decByteOffset_numpy(stream, size=None)¶ - Analyze a stream of char with any length of exception:
- 2, 4, or 8 bytes integers
Parameters: - stream – string representing the compressed data
- size – the size of the output array (of longInts)
Returns: 1D-ndarray
-
fabio.compression.decBzip2(stream)¶ Decompress a chunk of data using the bzip2 algorithm from Python
-
fabio.compression.decGzip(stream)¶ Decompress a chunk of data using the gzip algorithm from Python or alternatives if possible
-
fabio.compression.decKM4CCD(raw_8, raw_16=None, raw_32=None)¶ Modified byte offset decompressor used in Oxford Diffraction images
Note: Always expect little endian data on the disk
Parameters: - raw_8 – strings containing raw data with integer 8 bits
- raw_16 – strings containing raw data with integer 16 bits
- raw_32 – strings containing raw data with integer 32 bits
Returns: numpy.ndarray
-
fabio.compression.decPCK(stream, dim1=None, dim2=None, overflowPix=None, version=None, normal_start=None, swap_needed=None)¶ Modified CCP4 pck decompressor used in MAR345 images
Parameters: - raw – input string (bytes in python3)
- dim1,dim2 – optional parameters size
- overflowPix – optional parameters: number of overflowed pixels
- version – PCK version 1 or 2
- normal_start – position of the normal value section (can be auto-guessed)
- swap_needed – set to True when reading data from a foreign endianness (little on big or big on little)
:return : ndarray of 2D with the right size
-
fabio.compression.decTY1(raw_8, raw_16=None, raw_32=None)¶ Modified byte offset decompressor used in Oxford Diffraction images
Note: Always expect little endian data on the disk
Parameters: - raw_8 – strings containing raw data with integer 8 bits
- raw_16 – strings containing raw data with integer 16 bits
- raw_32 – strings containing raw data with integer 32 bits
Returns: numpy.ndarray
-
fabio.compression.decZlib(stream)¶ Decompress a chunk of data using the zlib algorithm from Python
-
fabio.compression.endianness()¶ Return the native endianness of the system
-
fabio.compression.md5sum(blob)¶ returns the md5sum of an object...
fabio.converters Module¶
Converter module. This is for the moment empty (populated only with almost pass through anonymous functions) but aims to be populated with more sofisticated translators ...
-
fabio.converters.convert_data(inp, outp, data)¶ Return data converted to the output format ... over-simplistic implementation for the moment ... :param inp,outp: input/output format like “cbfimage” :param data(ndarray): the actual dataset to be transformed
-
fabio.converters.convert_data_integer(data)¶ convert data to integer
-
fabio.converters.convert_header(inp, outp, header)¶ return header converted to the output format :param inp,outp: input/output format like “cbfimage” :param header(dict):the actual set of headers to be transformed
fabio.datIO Module¶
fabio.third_party.TiffIO Module¶
fabio.readbytestream Module¶
Reads a bytestream
- Authors: Jon Wright Henning O. Sorensen & Erik Knudsen
- ESRF Risoe National Laboratory
-
fabio.readbytestream.readbytestream(fil, offset, x, y, nbytespp, datatype='int', signed='n', swap='n', typeout=<type 'numpy.uint16'>)¶ Reads in a bytestream from a file (which may be a string indicating a filename, or an already opened file (should be “rb”)) offset is the position (in bytes) where the pixel data start nbytespp = number of bytes per pixel type can be int or float (4 bytes pp) or double (8 bytes pp) signed: normally signed data ‘y’, but ‘n’ to try to get back the right numbers when unsigned data are converted to signed (python once had no unsigned numeric types.) swap, normally do not bother, but ‘y’ to swap bytes typeout is the numpy type to output, normally uint16, but more if overflows occurred x and y are the pixel dimensions
TODO : Read in regions of interest
PLEASE LEAVE THE STRANGE INTERFACE ALONE - IT IS USEFUL FOR THE BRUKER FORMAT