FabIO Package
fabio Package
FabIO 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)[source]
Bases: object
A common object for images in fable
Contains a numpy array (.data) and dict of meta data (.header)
-
add(other)[source]
Add another Image - warning, does not clip to 16 bit images by default
-
static checkData(data=None)[source]
Empty for fabioimage but may be populated by others classes, especially for format accepting only integers
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)[source]
Convert a fabioimage object into another fabioimage object (with possible conversions)
:param dest: destination type “EDF”, “edfimage” or the class itself
-
getclassname()[source]
Retrieves the name of the class
:return: the name of the class
-
getframe(num)[source]
returns the file numbered ‘num’ in the series as a fabioimage
returns self.header
-
getmax()[source]
Find max value in self.data, caching for the future
-
getmean()[source]
return the mean
-
getmin()[source]
Find min value in self.data, caching for the future
-
getstddev()[source]
return the standard deviation
-
integrate_area(coords)[source]
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)[source]
Wrapper for read
-
make_slice(coords)[source]
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()[source]
returns the next file in the series as a fabioimage
-
previous()[source]
returns the previous file in the series as a fabioimage
-
read(filename, frame=None)[source]
To be overridden - fill in self.header and self.data
-
readROI(filename, frame=None, coords=None)[source]
Method reading Region of Interest.
This implementation is the trivial one, just doing read and crop
Call the _readheader function...
-
rebin(x_rebin_fact, y_rebin_fact, keep_I=True)[source]
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()[source]
Reset cache - call on changing data
-
save(fname)[source]
wrapper for write
-
toPIL16(filename=None)[source]
Convert to Python Imaging Library 16 bit greyscale image
FIXME - this should be handled by the libraries now
update the header entries
by default pass in a dict of key, values.
-
write(fname)[source]
To be overwritten - write the file
-
fabio.fabioimage.test()[source]
check some basic fabioimage functionality
General purpose utilities functions for fabio
-
class fabio.fabioutils.BZ2File(name, mode='r', buffering=0, compresslevel=9)[source]
Bases: bz2.BZ2File
Wrapper with lock
-
getSize()[source]
-
setSize(value)[source]
-
size
-
class fabio.fabioutils.DebugSemaphore(*arg, **kwarg)[source]
Bases: threading._Semaphore
threading.Semaphore like class with helper for fighting dead-locks
-
acquire(*arg, **kwarg)[source]
-
blocked = []
-
release(*arg, **kwarg)[source]
-
write_lock = <threading._Semaphore object at 0x41cfbf6c>
-
class fabio.fabioutils.File(name, mode='rb', buffering=0)[source]
Bases: file
wrapper for “file” with locking
-
getSize()[source]
-
setSize(size)[source]
-
size
-
class fabio.fabioutils.FilenameObject(stem=None, num=None, directory=None, format=None, extension=None, postnum=None, digits=4, filename=None)[source]
Bases: object
The ‘meaning’ of a filename ...
-
deconstruct_filename(filename)[source]
Break up a filename to get image type and number
-
str()[source]
Return a string representation
-
tostring()[source]
convert yourself to a string
-
class fabio.fabioutils.GzipFile(filename=None, mode=None, compresslevel=9, fileobj=None)[source]
Bases: gzip.GzipFile
Just a wrapper forgzip.GzipFile providing the correct seek capabilities for python 2.5
-
getSize()[source]
-
class fabio.fabioutils.StringIO(data, fname=None, mode='r')[source]
Bases: StringIO.StringIO
just an interface providing the name and mode property to a StringIO
BugFix for MacOSX mainly
-
getSize()[source]
-
setSize(size)[source]
-
size
-
class fabio.fabioutils.UnknownCompressedFile(name, mode='rb', buffering=0)[source]
Bases: fabio.fabioutils.File
wrapper for “File” with locking
-
fabio.fabioutils.construct_filename(filename, frame=None)[source]
Try to construct the filename for a given frame
-
fabio.fabioutils.deconstruct_filename(filename)[source]
Function for backward compatibility.
Deprecated
-
fabio.fabioutils.deprecated(func)[source]
used to deprecate a function/method: prints a lot of warning messages to enforce the modifaction of the code
extract file number
-
fabio.fabioutils.getnum(name)[source]
# try to figure out a file number
# guess it starts at the back
-
fabio.fabioutils.isAscii(name, listExcluded=None)[source]
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)[source]
jump to number
-
fabio.fabioutils.next_filename(name, padding=True)[source]
increment number
-
fabio.fabioutils.nice_int(s)[source]
Workaround that int(‘1.0’) raises an exception
Parameters: | s – string to be converted to integer |
-
fabio.fabioutils.numstem(name)[source]
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)[source]
Performs the padding of the string to the right size with the right pattern
-
fabio.fabioutils.previous_filename(name, padding=True)[source]
decrement number
-
fabio.fabioutils.toAscii(name, excluded=None)[source]
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
|
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
-
class fabio.file_series.file_series(list_of_strings)[source]
Bases: list
Represents a series of files to iterate
has an idea of a current position to do next and prev
- You also get from the list python superclass:
- append
count
extend
insert
pop
remove
reverse
sort
-
current()[source]
Current position in a sequence
-
current_image()[source]
Current image in sequence
-
current_object()[source]
Current image in sequence
-
first()[source]
First image in series
-
first_image()[source]
First image in a sequence
-
first_object()[source]
First image in a sequence
-
jump(num)[source]
Goto a position in sequence
-
jump_image(num)[source]
Jump to and read image
-
jump_object(num)[source]
Jump to and read image
-
last()[source]
Last in series
-
last_image()[source]
Last image in a sequence
-
last_object()[source]
Last image in a sequence
-
len()[source]
Number of files
-
next()[source]
Next in a sequence
-
next_image()[source]
Return the next image
-
next_object()[source]
Return the next image
-
previous()[source]
Prev in a sequence
-
previous_image()[source]
Return the previous image
-
previous_object()[source]
Return the previous image
-
class fabio.file_series.filename_series(filename)[source]
Much like the others, but created from a string filename
-
current()[source]
return current filename string
-
current_image()[source]
returns the current image as a fabioimage
-
current_object()[source]
returns the current filename as a fabio.FilenameObject
-
jump(num)[source]
jump to a specific number
-
jump_image(num)[source]
returns the image number as a fabioimage
-
jump_object(num)[source]
returns the filename num as a fabio.FilenameObject
-
next()[source]
increment number
-
next_image()[source]
returns the next image as a fabioimage
-
next_object()[source]
returns the next filename as a fabio.FilenameObject
-
prev_image()[source]
returns the previos image as a fabioimage
-
previous()[source]
decrement number
-
previous_object()[source]
returns the previous filename as a fabio.FilenameObject
-
fabio.file_series.new_file_series(first_object, nimages=0, step=1, traceback=False)[source]
A generator function that creates a file series starting from a a fabioimage.
Iterates through all images in a file (if more than 1), then proceeds to
the next file as determined by fabio.next_filename.
Parameters: |
- first_object – the starting fabioimage, which will be the first one yielded
in the sequence
- nimages – the maximum number of images to consider
step: step size, will yield the first and every step’th image until nimages
is reached. (e.g. nimages = 5, step = 2 will yield 3 images (0, 2, 4)
- traceback – if True causes it to print a traceback in the event of an
exception (missing image, etc.). Otherwise the calling routine can handle
the exception as it chooses
- yields – the next fabioimage in the series.
In the event there is an exception, it yields the sys.exec_info for the
exception instead. sys.exec_info is a tuple:
( exceptionType, exceptionValue, exceptionTraceback )
from which all the exception information can be obtained.
|
Suggested usage:
for obj in new_file_series( ... ):
if not isinstance(obj, fabio.fabioimage.fabioimage ):
# deal with errors like missing images, non readable files, etc
# e.g.
traceback.print_exception(obj[0], obj[1], obj[2])
-
fabio.file_series.new_file_series0(first_object, first=None, last=None, step=1)[source]
Created from a fabio image
first and last are file numbers
-
class fabio.file_series.numbered_file_series(stem, first, last, extension, digits=4, padding='Y', step=1)[source]
Bases: fabio.file_series.file_series
mydata0001.edf = “mydata” + 0001 + ”.edf”
mydata0002.edf = “mydata” + 0002 + ”.edf”
mydata0003.edf = “mydata” + 0003 + ”.edf”
- 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
-
fabio.openimage.do_magic(byts)[source]
Try to interpret the bytes starting the file as a magic number
return only the header
-
fabio.openimage.openimage(filename, frame=None)[source]
Try to open an image
- 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
-
class fabio.adscimage.adscimage(*args, **kwargs)[source]
Bases: fabio.fabioimage.fabioimage
Read an image in ADSC format (quite similar to edf?)
-
read(fname, frame=None)[source]
read in the file
-
write(fname)[source]
Write adsc format
-
fabio.adscimage.test()[source]
testcase
Authors: Gael Goret, Jerome Kieffer, ESRF, France
Emails: gael.goret@esrf.fr, jerome.kieffer@esrf.fr
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)[source]
Bases: fabio.fabioimage.fabioimage
This 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')[source]
Estimates the size of a file
-
read(fname, dim1, dim2, offset=0, bytecode='int32', endian='<')[source]
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)[source]
Decide if we need to byteswap
-
write(fname)[source]
- 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)[source]
Bases: fabio.fabioimage.fabioimage
Read 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.
-
SPACER = '\x1a\x04'
-
basic_translate(fname=None)[source]
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)[source]
Calculate the number of byte per pixel to get an optimal overflow table.
Generate headers (with some magic and guesses)
:param format can be 86 or 100
-
gen_overflow()[source]
Generate an overflow table
-
read(fname, frame=None)[source]
Read in and unpack the pixels (including overflow table
-
write(fname)[source]
Write a bruker image
-
fabio.brukerimage.test()[source]
a testcase
- 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)[source]
Bases: dict
This is the CIF class, it represents the CIF dictionary;
and as a a python dictionary thus inherits from the dict built in class.
-
BINARY_MARKER = '--CIF-BINARY-FORMAT-SECTION--'
-
BLANK = [' ', '\t', '\r', '\n', '\r\n', '\n\r']
-
EOL = ['\r', '\n', '\r\n', '\n\r']
-
static LoopHasKey(loop, key)[source]
Returns True if the key (string) exist in the array called loop
-
exists(sKey)[source]
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)[source]
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
-
static isAscii(_strIn)[source]
Check if all characters in a string are ascii,
Parameters: | _strIn (python string) – input string |
Returns: | boolean |
Return type: | boolean |
-
loadCHIPLOT(_strFilename)[source]
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)[source]
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)[source]
-
popitem(key)[source]
-
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)[source]
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)
:type param: string
-
tostring(_strFilename=None, linesep='n')[source]
Converts a cif dictionnary to a string according to the CIF syntax
Parameters: | _strFilename (string) – the name of the filename to be appended in the header of the CIF file |
Returns: | a sting that corresponds to the content of the CIF - file. |
-
class fabio.cbfimage.cbfimage(data=None, header=None, fname=None)[source]
Bases: fabio.fabioimage.fabioimage
Read the Cif Binary File data format
-
static checkData(data=None)[source]
-
read(fname, frame=None)[source]
- Read in header into self.header and
- the data into self.data
-
write(fname)[source]
write the file in CBF format
:param fname: name of the file
:type: string
- 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
-
class fabio.dm3image.dm3image(*args, **kwargs)[source]
Bases: fabio.fabioimage.fabioimage
Read and try to write the dm3 data format
-
read(fname, frame=None)[source]
-
read_data()[source]
-
read_tag_entry()[source]
-
read_tag_group()[source]
-
read_tag_type()[source]
-
readbytes(bytes_to_read, format, swap=True)[source]
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)[source]
Bases: object
A 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()[source]
-
getData()[source]
Unpack a binary blob according to the specification given in the header
Returns: | dataset as numpy.ndarray |
-
getEdfBlock(force_type=None, fit2dMode=False)[source]
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 countimg number of images at 1
|
Returns: | ascii header block
|
Return type: | python string with the concatenation of the ascii header and the binary data 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)[source]
-
setData(npa=None)[source]
Setter for data in edf frame
-
swap_needed()[source]
Decide if we need to byteswap
-
class fabio.edfimage.edfimage(data=None, header=None, header_keys=None, frames=None)[source]
Bases: fabio.fabioimage.fabioimage
Read and try to write the ESRF edf data format
-
appendFrame(frame=None, data=None, header=None)[source]
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
property: capsHeader of EDF file, i.e. the keys of the header in UPPER case.
Empty for fabioimage but may be populated by others classes
-
data
property: data of EDF file
deleter for edf capsHeader
-
delData()[source]
deleter for edf Data
Deleter for edf header
Deleter for edf header_keys
-
deleteFrame(frameNb=None)[source]
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)[source]
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)[source]
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()[source]
-
getByteCode()[source]
getter for edf headers keys in upper case
:return: data for current frame
:rtype: dict
-
getData()[source]
getter for edf Data
:return: data for current frame
:rtype: numpy.ndarray
-
getDim1()[source]
-
getDim2()[source]
-
getDims()[source]
Getter for the headers. used by the property header,
Getter for edf header_keys
-
getNbFrames()[source]
Getter for number of frames
-
getframe(num)[source]
returns the file numbered ‘num’ in the series as a fabioimage
property: header of EDF file
property: header_keys of EDF file
-
next()[source]
returns the next file in the series as a fabioimage
-
nframes
Getter for number of frames
-
previous()[source]
returns the previous file in the series as a fabioimage
-
read(fname, frame=None)[source]
- Read in header into self.header and
- the data into self.data
-
setBpp(_iVal)[source]
-
setByteCode(_iVal)[source]
Enforces the propagation of the header_keys to the list of frames
:param _data: numpy array representing data
-
setData(_data)[source]
Enforces the propagation of the data to the list of frames
:param _data: numpy array representing data
-
setDim1(_iVal)[source]
-
setDim2(_iVal)[source]
Enforces the propagation of the header to the list of frames
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)[source]
Setter for number of frames ... should do nothing. Here just to avoid bugs
-
swap_needed()[source]
Decide if we need to byteswap
-
unpack()[source]
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)[source]
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 |
Author: Andy Hammersley, ESRF
Translation into python/fabio: Jon Wright, ESRF.
Writer: Jérôme Kieffer
-
class fabio.fit2dmaskimage.fit2dmaskimage(data=None, header=None)[source]
Bases: fabio.fabioimage.fabioimage
Read and try to write Andy Hammersley’s mask format
-
static checkData(data=None)[source]
-
read(fname, frame=None)[source]
- Read in header into self.header and
- the data into self.data
-
write(fname)[source]
Try to write a file
- Read the fit2d ascii image output
-
-
class fabio.fit2dspreadsheetimage.fit2dspreadsheetimage(data=None, header=None)[source]
Bases: fabio.fabioimage.fabioimage
Read a fit2d ascii format
-
read(fname, frame=None)[source]
- Read in header into self.header and
- the data into self.data
-
class fabio.GEimage.GEimage(data=None, header=None)[source]
Bases: fabio.fabioimage.fabioimage
-
getframe(num)[source]
Returns a frame as a new fabioimage object
-
next()[source]
Get the next image in a series as a fabio image
-
previous()[source]
Get the previous image in a series as a fabio image
-
read(fname, frame=None)[source]
Read in header into self.header and
the data into self.data
-
write(fname, force_type=<type 'numpy.uint16'>)[source]
Not yet implemented
-
fabio.GEimage.demo()[source]
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]
-
class fabio.hdf5image.HDF5location(filename=None, h5path=None, slices=None, url=None)[source]
Bases: object
Handle URL like:
hdf5://filename:path[slice]
-
parse(url)[source]
Analyse a string of the form hdf5://filename:path[slice]
Parameters: | url – string of form of an hdf5-url |
-
set_index(idx)[source]
Set the current frame to idx
-
to_url()[source]
convert an HDF5 locate into an URL
-
class fabio.hdf5image.hdf5image(*arg, **kwargs)[source]
Bases: fabio.fabioimage.fabioimage
FabIO image class for Images from an HDF file
-
getframe(num)[source]
Returns a frame as a new fabioimage object
:param num: frame number
-
next()[source]
Get the next image in a series as a fabio image
-
previous()[source]
Get the previous image in a series as a fabio image
-
read(fname, frame=None)[source]
try to read image
:param fname: name of the file as hdf5://filename:path[slice]
-
write(fname, force_type=<type 'numpy.uint16'>)[source]
- 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
Information about the file format from Masakatzu Kobayashi is highly appreciated
-
class fabio.HiPiCimage.HiPiCimage(data=None, header=None)[source]
Bases: fabio.fabioimage.fabioimage
Read HiPic images e.g. collected with a Hamamatsu CCD camera
-
read(fname, frame=None)[source]
- Read in header into self.header and
- the data into self.data
- 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)[source]
Bases: fabio.fabioimage.fabioimage
Read the Nonius kcd data format
-
static checkData(data=None)[source]
-
read(fname, frame=None)[source]
- Read in header into self.header and
- the data into self.data
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.mar345image.mar345image(*args, **kwargs)[source]
Bases: fabio.fabioimage.fabioimage
-
static checkData(data=None)[source]
-
nb_overflow_pixels()[source]
-
read(fname, frame=None)[source]
Read a mar345 image
-
write(fname)[source]
Try to write mar345 file. This is still in beta version.
It uses CCP4 (LGPL) PCK1 algo from JPA
MRC image for FabIO
Authors: Jerome Kieffer
email: Jerome.Kieffer@terre-adelie.org
Specifications from:
http://ami.scripps.edu/software/mrctools/mrc_specification.php
-
class fabio.mrcimage.mrcimage(*arg, **kwargs)[source]
Bases: fabio.fabioimage.fabioimage
FabIO image class for Images from a mrc image stack
-
KEYS = ('NX', 'NY', 'NZ', 'MODE', 'NXSTART', 'NYSTART', 'NZSTART', 'MX', 'MY', 'MZ', 'CELL_A', 'CELL_B', 'CELL_C', 'CELL_ALPHA', 'CELL_BETA', 'CELL_GAMMA', 'MAPC', 'MAPR', 'MAPS', 'DMIN', 'DMAX', 'DMEAN', 'ISPG', 'NSYMBT', 'EXTRA', 'ORIGIN', 'MAP', 'MACHST', 'RMS', 'NLABL')
-
getframe(num)[source]
Returns a frame as a new fabioimage object
:param num: frame number
-
next()[source]
Get the next image in a series as a fabio image
-
previous()[source]
Get the previous image in a series as a fabio image
-
read(fname, frame=None)[source]
try to read image
:param fname: name of the file
:param frame:
-
write(fname, force_type=<type 'numpy.uint16'>)[source]
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?)
given a format and header interpret it
-
fabio.marccdimage.make_format(c_def_string)[source]
Reads the header definition in c and makes the format
string to pass to struct.unpack
-
class fabio.marccdimage.marccdimage(*args, **kwds)[source]
Bases: fabio.tifimage.tifimage
Read in data in mar ccd format, also
MarMosaic images, including header info
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)[source]
Bases: fabio.fabioimage.fabioimage
Oxford Diffraction Sapphire 3 images reader/writer class
-
static checkData(data=None)[source]
-
getCompressionRatio()[source]
calculate the compression factor obtained vs raw data
-
read(fname, frame=None)[source]
- Read in header into self.header and
- the data into self.data
-
write(fname)[source]
Write Oxford diffraction images: this is still beta
:param fname: output filename
-
class fabio.OXDimage.Section(size, dictHeader)[source]
Bases: object
Small helper class for writing binary headers
-
getSize(dtype)[source]
-
setData(key, offset, dtype, default=None)[source]
Parameters: |
- offset – int, starting position in the section
- key – name of the header key
- dtype – type of the data to insert (defines the size!)
|
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)[source]
Bases: fabio.tifimage.tifimage
Read in Pilatus format, also
pilatus images, including header info
Author: Jon Wright, ESRF.
-
fabio.pixiimage.demo(fname)[source]
-
class fabio.pixiimage.pixiimage(data=None, header=None)[source]
Bases: fabio.fabioimage.fabioimage
-
getframe(num)[source]
Returns a frame as a new fabioimage object
-
next()[source]
Get the next image in a series as a fabio image
-
previous()[source]
Get the previous image in a series as a fabio image
-
read(fname, frame=None)[source]
-
write(fname, force_type=<type 'numpy.uint16'>)[source]
- 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
-
class fabio.pnmimage.pnmimage(*arg, **kwargs)[source]
Bases: fabio.fabioimage.fabioimage
-
P1dec(buf, bytecode)[source]
-
P2dec(buf, bytecode)[source]
-
static P3dec(buf, bytecode)[source]
-
static P4dec(buf, bytecode)[source]
-
P5dec(buf, bytecode)[source]
-
static P6dec(buf, bytecode)[source]
-
static P7dec(buf, bytecode)[source]
-
static checkData(data=None)[source]
-
read(fname, frame=None)[source]
try to read PNM images
:param fname: name of the file
:param frame: not relevant here! PNM is always single framed
-
write(filename)[source]
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)[source]
Bases: fabio.fabioimage.fabioimage
FabIO 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)[source]
try to read image
:param fname: name of the file
:param frame:
-
rigakuKeys()[source]
-
swap_needed()[source]
not sure if this function is needed
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)[source]
Bases: object
-
unpack(instring, offset=-1)[source]
-
class fabio.tifimage.Image_File_Directory_entry(tag=0, tag_type=0, count=0, offset=0)[source]
Bases: object
-
unpack(strInput)[source]
Bases: object
-
class fabio.tifimage.tifimage(*args, **kwds)[source]
Bases: fabio.fabioimage.fabioimage
Images in TIF format
Wraps TiffIO
-
read(fname, frame=None)[source]
Wrapper for TiffIO.
-
write(fname)[source]
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?)...
- 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)[source]
Bases: fabio.fabioimage.fabioimage
Read the XSDataImage XML File data format
-
read(fname, frame=None)[source]
- Authors: Jérôme Kieffer, ESRF
- email:jerome.kieffer@esrf.fr
FabIO library containing compression and decompression algorithm for various
-
fabio.compression.compByteOffet_numpy(data)[source]
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)[source]
Modified CCP4 pck compressor used in MAR345 images
Parameters: | data – numpy.ndarray (square array) |
Returns: | compressed stream |
-
fabio.compression.compTY1(data)[source]
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.decByteOffet_cython(stream, size=None)[source]
- 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.decByteOffet_numpy(stream, size=None)[source]
- 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.decByteOffet_python(stream, size)[source]
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.decByteOffet_weave(stream, size)[source]
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)[source]
Decompress a chunk of data using the bzip2 algorithm from Python
-
fabio.compression.decGzip(stream)[source]
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
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)[source]
Modified CCP4 pck decompressor used in MAR345 images
Parameters: | stream – string or file |
Returns: | numpy.ndarray (square array) |
-
fabio.compression.decTY1(raw_8, raw_16=None, raw_32=None)[source]
Modified byte offset decompressor used in Oxford Diffraction images
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)[source]
Decompress a chunk of data using the zlib algorithm from Python
-
fabio.compression.endianness()[source]
Return the native endianness of the system
-
fabio.compression.md5sum(blob)[source]
returns the md5sum of an object...
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)[source]
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)[source]
convert data to integer
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
- 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, ESRF
-
class fabio.datIO.columnfile(data=None, clabels=None, rlabels=None, fname=None)[source]
Bases: fabio.datIO.fabiodata
Concrete fabiodata class
-
read(fname, frame=None)[source]
-
class fabio.datIO.fabiodata(data=None, clabels=None, rlabels=None, fname=None)[source]
Bases: object
A common class for dataIO in fable
Contains a 2d numpy array for keeping data, and two lists (clabels and rlabels)
containing labels for columns and rows respectively
-
read(fname=None, frame=None)[source]
To be overridden by format specific subclasses
-
class fabio.TiffIO.TiffIO(filename, mode=None, cache_length=20, mono_output=False)[source]
Bases: object
-
getData(nImage, **kw)[source]
-
getImage(nImage)[source]
-
getImageFileDirectories(fd=None)[source]
-
getInfo(nImage, **kw)[source]
-
getNumberOfImages()[source]
-
writeImage(image0, info=None, software=None, date=None)[source]
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'>)[source]
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