FabIO Package
fabio
Package
FabIO module
- fabio.benchmarks()
Run the benchmarks
- fabio.open(filename, frame=None)
Open an image.
It returns a FabioImage-class instance which can be used as a context manager to close the file at the termination.
with fabio.open("image.edf") as i: print(i.nframes) print(i.data)
- Parameters:
filename (Union[str,FilenameObject]) – A filename or a filename iterator.
frame (Union[int,None]) – A specific frame inside this file.
- Return type:
- fabio.open_series(filenames=None, first_filename=None, single_frame=None, fixed_frames=None, fixed_frame_number=None)
Create an object to iterate frames through a file series.
This function is a wrapper over
FileSeries
to facilitate simple uses of file series iterations.- Parameters:
filenames (Union[Generator,Iterator,List]) – Ordered list of filenames to process as a file series. It also can be a generator, and iterator, or
filename_series
orfile_series
objects.first_filename (str) – If provided iterate filenames from this filename and try to consecutivelly open next files. If this argument is specified the filenames have to unspecified. Internally it uses
filename_series
to iterate the filenames.single_frame (Union[Bool,None]) – If True, all files are supposed to contain only one frame.
fixed_frames (Union[Bool,None]) – If True, all files are supposed to contain the same amount of frames (this fixed amount will be reached from the first file of the serie).
fixed_frame_number (Union[Integer,None]) – If set, all files are supposed to contain the same amount of frames (sepecified by this argument)
- Return type:
- fabio.register(codec_class)
Register a codec class with the set of formats supported by fabio.
It is a transitional function to prepare the next comming version of fabio.
- On the current fabio library, when a module is imported, all the formats
inheriting FabioImage are automatically registred. And this function is doing nothing.
- On the next fabio library. Importing a module containing classes
inheriting FabioImage will not be registered. And this function will register the class.
The following source code will then provide the same behaviour on both fabio versions, and it is recommended to use it.
@fabio.register class MyCodec(fabio.fabioimage.FabioImage): pass
- fabio.tests()
Run the FabIO test suite.
If the test-images are not already installed (via the debian package for example), they need to be downloaded from sourceforge.net, which make take a while. Ensure your network connection is operational and your proxy settings are correct, for example:
export http_proxy=http://proxy.site.com:3128
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.FabioFrame(data=None, header=None)
Bases:
_FabioArray
Identify a frame
- property container
Returns the container providing this frame.
This FabioImage is stored as a weakref. If a reference to the file is not stored by user of the lib, this link is lost.
- Return type:
- property dtype
- property file_container
Returns the file container providing this frame.
This FabioImage is stored as a weakref. If a reference to the file is not stored by user of the lib, this link is lost.
- Return type:
- property file_index
Returns the index of this frame in in it’s file container.
- Return type:
int
- property header
Default header exposed by fabio
- Return type:
dict
- property index
Returns the index of this frame in in it’s container.
- Return type:
int
- next()
Returns the next frame from it’s file container.
- Return type:
- property shape
- class fabio.fabioimage.FabioImage(data=None, header=None)
Bases:
_FabioArray
A common object for images in fable
Contains a numpy array (.data) and dict of meta data (.header)
- RESERVED_HEADER_KEYS = []
- add(other)
Accumulate another fabioimage into the first image.
Warning, does not clip to 16 bit images by default
- Parameters:
other (FabioImage) – Another image to accumulate.
- static check_data(data=None)
Empty for fabioimage but may be populated by others classes, especially for format accepting only integers
- Parameters:
data – array like
- Returns:
numpy array or None
- static check_header(header=None)
Empty for fabioimage but may be populated by others classes
- Parameters:
header – dict like object
- Returns:
Ordered dict
- property classname
Retrieves the name of the class :return: the name of the class
- close()
- classmethod codec_name()
Returns the internal name of the codec
- convert(dest)
Convert a fabioimage object into another fabioimage object (with possible conversions) :param dest: destination type “EDF”, “edfimage” or the class itself :return: instance of the new class
- property dtype
- classmethod factory(name)
A kind of factory… for image_classes
- Parameters:
name (str) – name of the class to instantiate
- Returns:
an instance of the class
- Return type:
- frames()
Iterate all available frames stored in this image container.
- Return type:
Iterator[FabioFrame]
- get_frame(num)
Returns a frame from the this fabio image.
- Parameters:
num (int) – Number of frames (0 is the first frame)
- Return type:
- Raises:
IndexError – If the frame number is out of the available range.
- 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
- property incomplete_file
Returns true if the readed file is not complete.
- Return type:
bool
- load(*arg, **kwarg)
Wrapper for read
- next()
Returns the next file in the series as a fabioimage
- Raises:
IOError – When there is no next file in the series.
- property nframes
Returns the number of frames contained in this file
- Return type:
int
- 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
- Parameters:
x_rebin_fact (int) – x binning factor
y_rebin_fact (int) – y binning factor
keep_I (bool) – shall the signal increase ?
- save(fname)
wrapper for write
- property shape
- 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.fabioimage
alias of
FabioImage
fabio.fabioutils
Module
General purpose utilities functions for fabio
- fabio.fabioutils.AVAILABLE_COMPRESSED_EXTENSIONS = {'bz2', 'gz'}
Set of available compressed file extensions. Do not contains extensions for uninstalled optional dependancies.
- class fabio.fabioutils.BZ2File(name, mode='r', compresslevel=9)
Bases:
BZ2File
Wrapper with lock
- getSize()
- setSize(value)
- property size
- class fabio.fabioutils.BytesIO(data, fname=None, mode='r')
Bases:
BytesIO
just an interface providing the name and mode property to a BytesIO
BugFix for MacOSX mainly
- getSize()
- setSize(size)
- property size
- fabio.fabioutils.COMPRESSED_EXTENSIONS = {'bz2', 'gz'}
Set of compressed file extensions provided by Fabio
- class fabio.fabioutils.DebugSemaphore(*arg, **kwarg)
Bases:
Semaphore
threading.Semaphore like class with helper for fighting dead-locks
- acquire(*arg, **kwarg)
Acquire a semaphore, decrementing the internal counter by one.
When invoked without arguments: if the internal counter is larger than zero on entry, decrement it by one and return immediately. If it is zero on entry, block, waiting until some other thread has called release() to make it larger than zero. This is done with proper interlocking so that if multiple acquire() calls are blocked, release() will wake exactly one of them up. The implementation may pick one at random, so the order in which blocked threads are awakened should not be relied on. There is no return value in this case.
When invoked with blocking set to true, do the same thing as when called without arguments, and return true.
When invoked with blocking set to false, do not block. If a call without an argument would block, return false immediately; otherwise, do the same thing as when called without arguments, and return true.
When invoked with a timeout other than None, it will block for at most timeout seconds. If acquire does not complete successfully in that interval, return false. Return true otherwise.
- blocked = []
- release(*arg, **kwarg)
Release a semaphore, incrementing the internal counter by one or more.
When the counter is zero on entry and another thread is waiting for it to become larger than zero again, wake up that thread.
- write_lock = <threading.Semaphore at 0x7f7f6d5d3590: value=1>
- class fabio.fabioutils.File(name, mode='rb', temporary=False)
Bases:
FileIO
wrapper for “file” with locking
- close()
Close the file.
A closed file cannot be used for further I/O operations. close() may be called more than once without error.
- getSize()
- read(size=-1)
Read at most size bytes, returned as bytes.
Only makes one system call, so less data may be returned than requested. In non-blocking mode, returns None if no data is available. Return an empty bytes object at EOF.
- setSize(size)
- property size
- write(readablebuffer)
Write buffer b to file, return number of bytes written.
Only makes one system call, so not all of the data may be written. The number of bytes actually written is returned. In non-blocking mode, returns None if the write would block.
- class fabio.fabioutils.FilenameObject(stem=None, num=None, directory=None, format_=None, extension=None, postnum=None, digits=4, filename=None)
Bases:
object
The ‘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:
GzipFile
Just a wrapper for gzip.GzipFile providing the correct seek capabilities for python 2.5
- measure_size()
- exception fabio.fabioutils.NotGoodReader
Bases:
RuntimeError
The reader used is probably not the good one
- class fabio.fabioutils.OrderedDict
Bases:
OrderedDict
Ordered dictionary with pretty print
- class fabio.fabioutils.UnknownCompressedFile(name, mode='rb', buffering=0)
Bases:
File
wrapper 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.exists(path)
Test whether a path exists.
Replaces os.path.exists and handles in addition “::” based URI as defined in http://odo.pydata.org/en/latest/uri.html#separating-parts-with
- Parameters:
path – string
- Returns:
boolean
- 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
- Parameters:
mystr – input string
pattern – the filling pattern
size – the size of the block
- Returns:
the padded string to a multiple of size
- 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
- class fabio.file_series.FileSeries(filenames, single_frame=None, fixed_frames=None, fixed_frame_number=None)
Bases:
FabioImage
Provide a FabioImage abstracting a file series.
This abstraction provide the set of the filenames as the container of frames.
# Sequencial access through all the frames with FileSeries(filenames) as serie: for frame in serie.frames(): frame.data frame.header frame.index # index inside the file series frame.file_index # index inside the file (edf, tif) frame.file_container.filename # name of the source file # Random access to frames with FileSeries(filenames) as serie: frame = serie.get_frame(200) frame = serie.get_frame(201) frame = serie.get_frame(10) frame = serie.get_frame(2)
Files of the series can be set using a list of filenames, an iterator or a generator. It also supports a file series described using
filename_series
orfile_series
objects.# Iterate known files filenames = ["foo.edf", "bar.tif"] serie = FileSeries(filenames=filenames) # Iterate all images from foobar_0001.edf to 0003 filenames = numbered_file_series("foobar_", 1, 3, ".edf", digits=4) serie = FileSeries(filenames=filenames) # Iterate all images from foobar_0000.edf to the last consecutive number found filenames = filename_series("foobar_0000.edf") serie = FileSeries(filenames=filenames)
Options are provided to optimize a non-sequencial access by providing the amount of frames stored per files. This options (single_frame, fixed_frames and fixed_frame_number) can be used if we know an a priori on the way frames are stored in the files (the exact same amount of frames par file).
# Each files contains a single frame serie = FileSeries(filenames=filenames, single_frame=True) # Each files contains a fixed amout of frames. This value is # automatically found serie = FileSeries(filenames=filenames, fixed_frames=True) # Each files contains 100 frames (the last one could contain less) serie = FileSeries(filenames=filenames, fixed_frame_number=100)
- DEFAULT_EXTENSIONS = []
- close()
Close any IO handler openned.
- property data
- property dtype
- frames()
Returns an iterator throug all frames of all filenames of this file series.
- getframe(num)
returns the file numbered ‘num’ in the series as a fabioimage
- property header
- property nframes
Returns the number of available frames in the full file series.
- Return type:
int
- property shape
- use_edf_shortcut
If true a custom file sequencial file reader is used for EDF formats
- class fabio.file_series.file_series(list_of_strings)
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()
Current position in a sequence
- current_image()
Current image in sequence
- Returns:
fabioimage
- current_object()
Current image in sequence
- Returns:
file_object
- first()
First image in series
- first_image()
First image in a sequence
- Returns:
fabioimage
- first_object()
First image in a sequence
- Returns:
file_object
- jump(num)
Goto a position in sequence
- jump_image(num)
Jump to and read image
- Returns:
fabioimage
- jump_object(num)
Jump to and read image
- Returns:
file_object
- last()
Last in series
- last_image()
Last image in a sequence
- Returns:
fabioimage
- last_object()
Last image in a sequence
- Returns:
file_object
- len()
Number of files
- next()
Next in a sequence
- next_image()
Return the next image
- Returns:
fabioimage
- next_object()
Return the next image
- Returns:
file_object
- previous()
Prev in a sequence
- previous_image()
Return the previous image
- Returns:
fabioimage
- previous_object()
Return the previous image
- Returns:
file_object
- class fabio.file_series.filename_series(filename)
Bases:
object
Iterator through a list of files indexed by a number.
Supports next, prevous and jump accessors.
- Parameters:
filename (Union[str,FilenameObject]) – The first filename of the iteration.
- current()
return current filename string
- current_image()
returns the current image as a fabioimage
- current_object()
returns the current filename as a fabio.FilenameObject
- jump(num)
jump to a specific number
- jump_image(num)
returns the image number as a fabioimage
- jump_object(num)
returns the filename num as a fabio.FilenameObject
- next()
increment number
- next_image()
returns the next image as a fabioimage
- next_object()
returns the next filename as a fabio.FilenameObject
- prev_image()
returns the previos image as a fabioimage
- previous()
decrement number
- previous_object()
returns the previous filename as a fabio.FilenameObject
- fabio.file_series.new_file_series(first_object, nimages=0, step=1, traceback=False)
A generator function that creates a file series starting from 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 as a logging error. Otherwise the exception is logged as a debug message. 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): # In case of problem (missing images, non readable files, etc) # obj contains the result of exc_info traceback.print_exception(obj[0], obj[1], obj[2])
- fabio.file_series.new_file_series0(first_object, first=None, last=None, step=1)
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)
Bases:
file_series
mydata0001.edf = “mydata” + 0001 + “.edf” mydata0002.edf = “mydata” + 0002 + “.edf” mydata0003.edf = “mydata” + 0003 + “.edf”
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 mods for APS GE by JVB
- fabio.openimage.do_magic(byts, filename)
Try to interpret the bytes starting the file as a magic number
- fabio.openimage.open_series(filenames=None, first_filename=None, single_frame=None, fixed_frames=None, fixed_frame_number=None)
Create an object to iterate frames through a file series.
This function is a wrapper over
FileSeries
to facilitate simple uses of file series iterations.- Parameters:
filenames (Union[Generator,Iterator,List]) – Ordered list of filenames to process as a file series. It also can be a generator, and iterator, or
filename_series
orfile_series
objects.first_filename (str) – If provided iterate filenames from this filename and try to consecutivelly open next files. If this argument is specified the filenames have to unspecified. Internally it uses
filename_series
to iterate the filenames.single_frame (Union[Bool,None]) – If True, all files are supposed to contain only one frame.
fixed_frames (Union[Bool,None]) – If True, all files are supposed to contain the same amount of frames (this fixed amount will be reached from the first file of the serie).
fixed_frame_number (Union[Integer,None]) – If set, all files are supposed to contain the same amount of frames (sepecified by this argument)
- Return type:
FileSeries
- fabio.openimage.openheader(filename)
return only the header
- fabio.openimage.openimage(filename, frame=None)
Open an image.
It returns a FabioImage-class instance which can be used as a context manager to close the file at the termination.
with fabio.open("image.edf") as i: print(i.nframes) print(i.data)
- Parameters:
filename (Union[str,FilenameObject]) – A filename or a filename iterator.
frame (Union[int,None]) – A specific frame inside this file.
- Return type:
fabio.adscimage
Module
Compatibility code with ADSC format.
This module is now renamed into fabio.dtrekimage
.
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:
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.
- DEFAULT_EXTENSIONS = ['bin']
- DESCRIPTION = 'Binary format (none-compressed 2D images)'
- 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 (str) – file name
dim1 (int) – image dimensions (Fast index)
dim2 (int) – image dimensions (Slow index)
offset (int) – 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 litte or big endian (“<” or “>”)
- static swap_needed(endian)
Decide if we need to byteswap
- write(fname)
To be overwritten - write the file
- fabio.binaryimage.binaryimage
alias of
BinaryImage
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 Sigmund Neher, GWDG, Göttingen, Germany
- class fabio.bruker100image.Bruker100Image(data=None, header=None)
Bases:
BrukerImage
- DEFAULT_EXTENSIONS = ['sfrm']
- DESCRIPTION = 'SFRM File format used by Bruker detectors (version 100)'
- bpp_to_numpy = {1: <class 'numpy.uint8'>, 2: <class 'numpy.uint16'>, 4: <class 'numpy.int32'>}
- gen_header()
Generate headers (with some magic and guesses) format is Bruker100
- read(fname, frame=None)
Read the data.
Data is stored in three blocks:
data (uint8 mainly when bpp=1), possibly int32 if bpp=4
overflow1 (2 bytes/value in uint16)
overflow2 (4 bytes/value in int32)
underflow (int8, int16 or int32).
The blocks are zero padded to a multiple of 16 bytes.
- version = 100
- write(fname)
Write a bruker100 format image
- fabio.bruker100image.bruker100image
alias of
Bruker100Image
- fabio.bruker100image.mround(value, multiple=16)
Round a value up to the multiple of multiple
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:
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.
- DEFAULT_EXTENSIONS = []
- DESCRIPTION = 'File format used by Bruker detectors (version 86)'
- 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: <class 'numpy.uint8'>, 2: <class 'numpy.uint16'>, 4: <class '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)
- gen_overflow()
Generate an overflow table
- read(fname, frame=None)
Read in and unpack the pixels (including overflow table
- version = 86
- write(fname)
Write a bruker image
- fabio.brukerimage.brukerimage
alias of
BrukerImage
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:
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.
keys are always unicode (str in python3) values are bytes
- BINARY_MARKER = b'--CIF-BINARY-FORMAT-SECTION--'
- BLANK = [b' ', b'\t', b'\r', b'\n', b'\r\n', b'\n\r']
- DATA = b'data_'
- DOT = b'.'
- DOUBLE_QUOTE = b'"'
- EOL = [b'\r', b'\n', b'\r\n', b'\n\r']
- GLOBAL = b'global_'
- HASH = b'#'
- LOOP = b'loop_'
- static LoopHasKey(loop, key)
Returns True if the key (string) exist in the array called loop
- QUESTIONMARK = b'?'
- SAVE = b'save_'
- SEMICOLUMN = b';'
- SINGLE_QUOTE = b"'"
- START_COMMENT = (b"'", b'"')
- STOP = b'stop_'
- UNDERSCORE = 95
- exists(sKey)
Check if the key exists in the CIF and is non empty.
- Parameters:
sKey (str) – CIF key
cif – CIF dictionary
- Returns:
True if the key exists in the CIF dictionary and is non empty
- Return type:
boolean
- existsInLoop(sKey)
Check if the key exists in the CIF dictionary.
- Parameters:
sKey (str) – CIF key
cif – CIF dictionary
- Returns:
True if the key exists in the CIF dictionary and is non empty
- Return type:
boolean
- static isAscii(text)
Check if all characters in a string are ascii,
- Parameters:
text (str) – 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 (str) – 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
- Parameters:
_strFilename (str) – the name of the file to open
- Returns:
None
- pop(k[, d]) v, remove specified key and return the corresponding value.
If the key is not found, return the default if given; otherwise, raise a KeyError.
- popitem(key, default=None)
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
- readCIF(_strFilename, _bKeepComment=False)
Load the CIF file and populates the CIF dictionary into the object
- Parameters:
_strFilename (str) – the name of the file to open
- Returns:
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.
- Parameters:
_strFilename (str) – the name of the filename to be appended in the header of the CIF file.
linesep – default line separation (can be ‘n’ or ‘rn’).
- Returns:
a string that corresponds to the content of the CIF-file.
- class fabio.cbfimage.CbfImage(data=None, header=None, fname=None)
Bases:
FabioImage
Read the Cif Binary File data format
- BINARAY_SECTION = b'--CIF-BINARY-FORMAT-SECTION--'
- CIF_BINARY_BLOCK_KEY = '_array_data.data'
- DEFAULT_EXTENSIONS = ['cbf']
- DESCRIPTION = 'Cif Binary Files format (used by the Pilatus detectors and others)'
- PADDING = 512
- STARTER = b'\x0c\x1a\x04\xd5'
- static checkData(data=None)
- read(fname, frame=None, check_MD5=True, only_raw=False)
Read in header into self.header and the data into self.data
- Parameters:
fname (str) – name of the file
- Returns:
fabioimage instance
- read_raw_data(infile)
Read and return the raw data chunk
- Parameters:
infile – opened file at correct position
- Returns:
raw compressed stream
- write(fname)
write the file in CBF format :param str fname: name of the file
- class fabio.cbfimage.PilatusHeader(content=None, convention='PILATUS_1.2')
Bases:
object
- KEYWORDS = {'Alpha': PilatusKey(keyword='Alpha', key_index=0, value_indices=[1], types=[<class 'float'>], repr='Alpha {} deg.'), 'Angle_increment': PilatusKey(keyword='Angle_increment', key_index=0, value_indices=[1], types=[<class 'float'>], repr='Angle_increment {} deg.'), 'Beam_xy': PilatusKey(keyword='Beam_xy', key_index=0, value_indices=[1, 2], types=[<class 'float'>, <class 'float'>], repr='Beam_xy ({}, {}) pixels'), 'Chi': PilatusKey(keyword='Chi', key_index=0, value_indices=[1], types=[<class 'float'>], repr='Chi {} deg.'), 'Chi_increment': PilatusKey(keyword='Chi_increment', key_index=0, value_indices=[1], types=[<class 'float'>], repr='Chi_increment {} deg.'), 'Count_cutoff': PilatusKey(keyword='Count_cutoff', key_index=0, value_indices=[1], types=[<class 'int'>], repr='Count_cutoff {} counts'), 'Detector': PilatusKey(keyword='Detector', key_index=0, value_indices=slice(1, None, None), types=<class 'str'>, repr='Detector: {}'), 'Detector_2theta': PilatusKey(keyword='Detector_2theta', key_index=0, value_indices=[1], types=[<class 'float'>], repr='Detector_2theta {} deg.'), 'Detector_Voffset': PilatusKey(keyword='Detector_Voffset', key_index=0, value_indices=[1], types=[<class 'float'>], repr='Detector_Voffset {} m'), 'Detector_distance': PilatusKey(keyword='Detector_distance', key_index=0, value_indices=[1], types=[<class 'float'>], repr='Detector_distance {} m'), 'Energy_range': PilatusKey(keyword='Energy_range', key_index=0, value_indices=[1, 2], types=[<class 'float'>, <class 'float'>], repr='Energy_range {} {} eV'), 'Excluded_pixels': PilatusKey(keyword='Excluded_pixels', key_index=0, value_indices=[1], types=[<class 'str'>], repr='Excluded_pixels: {}'), 'Exposure_period': PilatusKey(keyword='Exposure_period', key_index=0, value_indices=[1], types=[<class 'float'>], repr='Exposure_period {} s'), 'Exposure_time': PilatusKey(keyword='Exposure_time', key_index=0, value_indices=[1], types=[<class 'float'>], repr='Exposure_time {} s'), 'Filter_transmission': PilatusKey(keyword='Filter_transmission', key_index=0, value_indices=[1], types=[<class 'float'>], repr='Filter_transmission {}'), 'Flat_field': PilatusKey(keyword='Flat_field', key_index=0, value_indices=[1], types=[<class 'str'>], repr='Flat_field: {}'), 'Flux': PilatusKey(keyword='Flux', key_index=0, value_indices=[1], types=[<class 'float'>], repr='Flux {}'), 'Gain_setting': PilatusKey(keyword='Gain_setting', key_index=0, value_indices=[1, 2], types=[<class 'str'>, <class 'str'>], repr='Gain_setting: {} {} (vrf = -0.200)'), 'Image_path': PilatusKey(keyword='Image_path', key_index=0, value_indices=[1], types=[<class 'str'>], repr='Image_path: {}'), 'Kappa': PilatusKey(keyword='Kappa', key_index=0, value_indices=[1], types=[<class 'float'>], repr='Kappa {} deg.'), 'N_excluded_pixels': PilatusKey(keyword='N_excluded_pixels', key_index=0, value_indices=[1], types=[<class 'int'>], repr='N_excluded_pixels = {}'), 'N_oscillations': PilatusKey(keyword=" ('N_oscillations", key_index=0, value_indices=[1], types=[<class 'int'>], repr='N_oscillations {}'), 'Omega': PilatusKey(keyword='Omega', key_index=0, value_indices=[1], types=[<class 'float'>], repr='Omega {} deg.'), 'Omega_increment': PilatusKey(keyword='Omega_increment', key_index=0, value_indices=[1], types=[<class 'float'>], repr='Omega_increment {} deg.'), 'Oscillation_axis': PilatusKey(keyword='Oscillation_axis', key_index=0, value_indices=[1], types=[<class 'str'>], repr='Oscillation_axis {}'), 'Phi': PilatusKey(keyword='Phi', key_index=0, value_indices=[1], types=[<class 'float'>], repr='Phi {} deg.'), 'Phi_increment': PilatusKey(keyword='Phi_increment', key_index=0, value_indices=[1], types=[<class 'float'>], repr='Phi_increment {} deg.'), 'Pixel_size': PilatusKey(keyword='Pixel_size', key_index=0, value_indices=[1, 4], types=[<class 'float'>, <class 'float'>], repr='Pixel_size {} m x {} m'), 'Polarization': PilatusKey(keyword='Polarization', key_index=0, value_indices=[1], types=[<class 'float'>], repr='Polarization {}'), 'Position_increment': PilatusKey(keyword='Position_increment', key_index=0, value_indices=[1], types=[<class 'float'>], repr='Position_increment'), 'Shutter_time': PilatusKey(keyword='Shutter_time', key_index=0, value_indices=[1], types=[<class 'float'>], repr='Shutter_time {} s'), 'Start_angle': PilatusKey(keyword='Start_angle', key_index=0, value_indices=[1], types=[<class 'float'>], repr='Start_angle {} deg.'), 'Start_position': PilatusKey(keyword='Start_position', key_index=0, value_indices=[1], types=[<class 'float'>], repr='Start_position {}'), 'Tau': PilatusKey(keyword='Tau', key_index=0, value_indices=[1], types=[<class 'float'>], repr='Tau = {} s'), 'Threshold_setting': PilatusKey(keyword='Threshold_setting', key_index=0, value_indices=[1], types=[<class 'float'>], repr='Threshold_setting: {} eV'), 'Trim_file': PilatusKey(keyword='Trim_file', key_index=0, value_indices=[1], types=[<class 'str'>], repr='Trim_file: {}'), 'Wavelength': PilatusKey(keyword='Wavelength', key_index=0, value_indices=[1], types=[<class 'float'>], repr='Wavelength {} A'), 'sensor': PilatusKey(keyword='sensor', key_index=1, value_indices=[0, 3], types=[<class 'str'>, <class 'float'>], repr='{} sensor, thickness {} m')}
- SPACE_LIKE = '()#:=,'
- classmethod clean_string(input_string)
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
- class fabio.dm3image.Dm3Image(*args, **kwargs)
Bases:
FabioImage
Read and try to write the dm3 data format
- DEFAULT_EXTENSIONS = ['dm3']
- DESCRIPTION = 'Digital Micrograph DM3 file format'
- read(fname, frame=None)
To be overridden - fill in self.header and self.data
- read_data()
- read_tag_entry()
- read_tag_group()
- read_tag_type()
- readbytes(bytes_to_read, format, swap=True)
fabio.dtrekimage
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.dtrekimage.DtrekImage(*args, **kwargs)
Bases:
FabioImage
Read an image using the d*TREK format.
This format is used to process X-ray diffraction data from area detectors. It supports processing of data from multiple detector types (imaging plates, CCDs and pixel arrays) and from multiple vendors (Rigaku, Mar, Dectris, Bruker and ADSC).
Rigaku providing a specification.
- DEFAULT_EXTENSIONS = ['img']
- DESCRIPTION = 'D*trek format (Rigaku specification 1.1)'
- read(fname, frame=None)
read in the file
- swap_needed(check=True)
Returns True if the header does not use the same endianness than the system.
- Return type:
bool
- write(fname)
Write d*TREK format
fabio.edfimage
Module
License: MIT
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.EdfFrame(data=None, header=None, number=None)
Bases:
FabioFrame
A class representing a single frame in an EDF file
- bfname
If set, the data must be read from this file and not from the blob The external file must be located in the same folder as the edf data file. It must be different from the edf data file.
- bfstart
Start position of the raw data in the external file.
- blobsize
Size of the raw data blob in the file (including padding)
- property data
Returns the data after unpacking it if needed.
- Returns:
dataset as numpy.ndarray
- file
Opened file object with locking capabilities
- getData()
Returns the data after unpacking it if needed.
- Returns:
dataset as numpy.ndarray
- getEdfBlock(force_type=None, fit2dMode=False)
- static get_data_counts(shape=None)
Counts items specified by shape (returns 1 for shape==None)
- Param:
tuple shape
- Returns:
int counts
- static get_data_rank(header=None, capsHeader=None)
Get the rank of the data array by searching the header for the key DIM_i with the highest index i. The smallest index of DIM_i is 1 (1-based). The highest index is equal to the rank.
- Param:
dict header
- Param:
dict capsHeader (optional)
- Returns:
int rank
- static get_data_shape(rank=0, header=None, capsHeader=None)
Returns a tuple with the number of dimensions up to the given rank. The dimensions DIM_i are read from the header dictionary. The values of missing DIM_i keys are set to 1, except DIM_1 which has the default 0.
The DIM_i header indices are 1-based and are equal to the number of elements in each dimension of a data array, starting with DIM_1 as the number of elements of a linear array, DIM_2 is the number of stacked linear arrays with DIM_1 elements, etc. (FORTRAN-type indexing).
The shape tuple is filled from the end to the beginning with the values of DIM_i, i.e. shape[0] is equal to value of DIM_rank, shape[rank-i] is equal to the value of DIM_i (e.g. for rank==2, shape[0]==value(DIM_2), shape[1]==value(DIM_1)). The returned shape tuple can be used with numpy arrays.
- Param:
int rank
- Param:
dict header
- Param:
dict capsHeader (optional)
- Returns:
tuple shape
- get_edf_block(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
- property iFrame
Returns the frame index of this frame
- setData(npa=None)
Setter for data in edf frame
- size
Size of the retrieved data (after unpacking and decompressing)
- start
Start position of the raw data blob in the file
- swap_needed()
Decide if we need to byteswap
- class fabio.edfimage.EdfImage(data=None, header=None, frames=None, generalframe=None)
Bases:
FabioImage
Read and try to write the ESRF edf data format
- DEFAULT_EXTENSIONS = ['edf', 'cor']
- DESCRIPTION = 'European Synchrotron Radiation Facility data format'
- RESERVED_HEADER_KEYS = ['HEADERID', 'IMAGE', 'BYTEORDER', 'DATATYPE', 'DIM_1', 'DIM_2', 'DIM_3', 'SIZE']
- appendFrame(frame=None, data=None, header=None)
- append_frame(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
- property bpp
Getter for bpp: data superseeds _bpp
- property bytecode
Getter for bpp: data superseeds _bytecode
- static check_header(header=None)
Empty for FabioImage but may be populated by other classes
- property data
- delData()
deleter for edf Data
- delHeader()
Deleter for edf header
- deleteFrame(frameNb=None)
- delete_frame(frameNb=None)
Method used to remove a frame from an EDF image. by default the last one is removed. :param int frameNb: frame number to remove, by default the last.
- property dim1
- property dim2
- property dims
- property dtype
- fastReadData(filename)
- fastReadROI(filename, coords=None)
- fast_read_data(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
- fast_read_roi(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.
- Parameters:
filename – name of another file with the same structure.
- Paran coords:
2 tuple of slices (RECOMMANDED) or a 4 tuple (NOT RECOMMANDED, cryptic fabian convention)
- Returns:
ROI-data from another file using positions from current EdfImage
- Return type:
numpy 2darray
- getBpp()
- getByteCode()
- 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,
- getNbFrames()
Getter for number of frames
- getframe(num)
returns the file numbered ‘num’ in the series as a FabioImage
- property header
- property incomplete_data
- property incomplete_file
Returns true if the file is not complete.
- Return type:
bool
- isIncompleteData()
- classmethod lazy_iterator(filename)
Iterates over the frames of an EDF multi-frame file.
This function optimizes sequential access to multi-frame EDF files by avoiding to read the whole file at first in order to get the number of frames and build an index of frames for faster random access.
Usage:
>>> from fabio.edfimage import EdfImage
>>> for frame in EdfImage.lazy_iterator("multiframe.edf"): ... print('Header:', frame.header) ... print('Data:', frame.data)
- Parameters:
filename (str) – File name of the EDF file to read
- Yield:
frames one after the other
- next()
Returns the next file in the series as a fabioimage
- Raises:
IOError – When there is no next file or image in the series.
- property nframes
Returns the number of frames contained in this file
- Return type:
int
- 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=None, _iVal=None)
- setByteCode(iVal=None, _iVal=None)
- setData(_data=None)
Enforces the propagation of the data to the list of frames :param data: numpy array representing data
- setDim1(_iVal=None)
- setDim2(_iVal=None)
- setHeader(_dictHeader)
Enforces the propagation of the header to the list of frames
- setNbFrames(val)
Setter for number of frames … should do nothing. Here just to avoid bugs
- property shape
- swap_needed()
Decide if we need to byteswap
- Returns:
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”
- fabio.edfimage.Frame
Compatibility code with fabio <= 0.8
- class fabio.edfimage.HeaderBlockType(header, header_size, binary_size, data_format_version)
Bases:
tuple
- binary_size
Alias for field number 2
- data_format_version
Alias for field number 3
- header
Alias for field number 0
- header_size
Alias for field number 1
- exception fabio.edfimage.MalformedHeaderError
Bases:
OSError
Raised when a header is malformed
fabio.eigerimage
Module
Eiger data/master file reader for FabIO
Eiger data files are HDF5 files with one group called “entry” and a dataset called “data” in it (now in a data group).
Those dataset are usually compressed using LZ4 and/or bitshuffle compression:
H5py (>2.5) and libhdf5 (>1.8.10) with the corresponding compression plugin are needed to actually read the data. Under windows, those plugins can easily be installed via this repository: https://github.com/silx-kit/hdf5plugin
- class fabio.eigerimage.EigerImage(data=None, header=None)
Bases:
FabioImage
FabIO image class for Images from Eiger data files (HDF5)
- DEFAULT_EXTENSIONS = ['h5', 'hdf5']
- DESCRIPTION = 'Eiger data files based on HDF5'
- close()
- property data
- get_data()
- getframe(num)
returns the frame numbered ‘num’ in the stack if applicable
- next()
Returns the next file in the series as a fabioimage
- Raises:
IOError – When there is no next file or image in the series.
- property nframes
Returns the number of frames contained in this file
- Return type:
int
- previous()
returns the previous file in the series as a FabioImage
- read(fname, frame=None)
Try to read image
- Parameters:
fname – name of the file
frame – number of the frame
- set_data(data, index=None)
Set the data for frame index
- Parameters:
data – numpy array
index (int) – index of the frame (by default: current one)
- Raises:
IndexError – If the frame number is out of the available range.
- write(fname)
try to write image :param fname: name of the file
- fabio.eigerimage.eigerimage
alias of
EigerImage
fabio.fit2dimage
Module
FabIO reader for Fit2D binary images
TODO: handle big-endian files
- class fabio.fit2dimage.Fit2dImage(*arg, **kwargs)
Bases:
FabioImage
FabIO image class for Images for XXX detector
- BUFFER_SIZE = 512
- DEFAULT_EXTENSIONS = ['f2d']
- DESCRIPTION = 'Fit2d file format'
- ENC = 'ascii'
- PIXELS_PER_CHUNK = 128
- read(fname, frame=None)
try to read image
- Parameters:
fname – name of the file
- fabio.fit2dimage.fit2dimage
alias of
Fit2dImage
- fabio.fit2dimage.hex_to(stg, type_='int')
convert a 8-byte-long string (bytes) into an int or a float
- Parameters:
stg – bytes string
type (str) – “int” or “float”
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:
FabioImage
Read and try to write Andy Hammersley’s mask format
- DEFAULT_EXTENSIONS = ['msk']
- DESCRIPTION = 'Fit2d mask file format'
- static check_data(data=None)
Empty for fabioimage but may be populated by others classes, especially for format accepting only integers
- Parameters:
data – array like
- Returns:
numpy array or None
- read(fname, frame=None)
- Read in header into self.header and
the data into self.data
- write(fname)
Try to write a file
- fabio.fit2dmaskimage.fit2dmaskimage
alias of
Fit2dMaskImage
fabio.fit2dspreadsheetimage
Module
- Read the fit2d ascii image output
Jon Wright, ESRF
- class fabio.fit2dspreadsheetimage.Fit2dSpreadsheetImage(data=None, header=None)
Bases:
FabioImage
Read a fit2d ascii format
- DEFAULT_EXTENSIONS = ['spr']
- DESCRIPTION = 'Fit2d spreadsheet ascii file format'
- read(fname, frame=None)
- Read in header into self.header and
the data into self.data
- fabio.fit2dspreadsheetimage.fit2dspreadsheetimage
alias of
Fit2dSpreadsheetImage
fabio.GEimage
Module
Reads the header from a GE a-Si Angio Detector using version 8001 of the header from file:
c:adeptcoreDefaultImageInfoConfig.csv
- class fabio.GEimage.GeImage(data=None, header=None)
Bases:
FabioImage
GE a-Si Angio detector file format.
- BITDEPTH_TO_DATATYPES = {8: <class 'numpy.uint8'>, 16: <class 'numpy.uint16'>, 32: <class 'numpy.uint32'>}
- BLANKED_HEADER_METADATA = {'ImageDepthInBits': 16, 'NumberOfColsInFrame': 2048, 'NumberOfRowsInFrame': 2048, 'StandardHeaderSizeInBytes': 8192, 'UserHeaderSizeInBytes': 0}
- BLANK_IMAGE_FORMAT = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
At APS they blanked the header with 8192 bytes of zeros when updating the GE firmware. This happened in ~2018 to the best of my knowledge, and a lot of data has been measured with the GE detectors that are missing the magic bytes and header.
- DEFAULT_EXTENSIONS = []
- DESCRIPTION = 'GE a-Si Angio detector file format'
- getframe(num)
Return 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 header into self.header and the data into self.data.
fabio.hdf5image
Module
HDF5 image for FabIO
Authors: Jerome Kieffer email: Jerome.Kieffer@terre-adelie.org
Specifications: input should being the form:
filename::path
Only supports ndim=2 or 3 (exposed as a stack of images
- class fabio.hdf5image.Hdf5Frame(hdf5image, frame_num)
Bases:
FabioFrame
Identify a slice of dataset from an HDF5 file
- class fabio.hdf5image.Hdf5Image(*arg, **kwargs)
Bases:
FabioImage
FabIO image class for Images from an HDF file
filename::dataset
- DEFAULT_EXTENSIONS = ['h5']
- DESCRIPTION = 'Hierarchical Data Format HDF5 flat reader'
- close()
- 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: filename::datasetpath
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
- fabio.HiPiCimage.HiPiCimage
alias of
HipicImage
- class fabio.HiPiCimage.HipicImage(data=None, header=None)
Bases:
FabioImage
Read HiPic images e.g. collected with a Hamamatsu CCD camera
- DEFAULT_EXTENSIONS = ['img']
- DESCRIPTION = 'HiPic file format from Hamamatsu CCD cameras'
- 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:
FabioImage
Read the Nonius kcd data format
- DEFAULT_EXTENSIONS = ['kcd']
- DESCRIPTION = "KCD file format from Nonius's KappaCCD diffractometer"
- static checkData(data=None)
- read(fname, frame=None)
- Read in header into self.header and
the data into self.data
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:
FabioImage
- DEFAULT_EXTENSIONS = ['mar2300', 'mar1200', 'mar1600', 'mar2000', 'mar3450', 'mar3000', 'mar2400', 'mar1800']
- DESCRIPTION = 'File format from Mar345 imaging plate and Mar555 flat panel'
- 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. It uses a MIT implementation of the CCP4 (LGPL) PCK1 algo from JPA
- fabio.mar345image.mar345image
alias of
Mar345Image
fabio.mrcimage
Module
MRC image for FabIO
Authors: Jerome Kieffer email: Jerome.Kieffer@terre-adelie.org
Specifications from: http://ami.scripps.edu/software/mrctools/mrc_specification.php New version on: https://www.ccpem.ac.uk/mrc_format/mrc_format.php https://www.fei-software-center.com/tem-apps/MRC-2014-Specifications/
- class fabio.mrcimage.MrcImage(data=None, header=None)
Bases:
FabioImage
FabIO image class for Images from a mrc image stack
- DEFAULT_EXTENSIONS = ['mrc', 'map', 'fei']
- DESCRIPTION = 'Medical Research Council file format for 3D electron density and 2D images'
- 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)
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 :param frame:
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?)
- class fabio.marccdimage.MarccdImage(*args, **kwds)
Bases:
TifImage
Read in data in mar ccd format, also MarMosaic images, including header info
- DEFAULT_EXTENSIONS = ['mccd']
- DESCRIPTION = 'File format from MarCCD and MarMosaic images'
- 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
- fabio.marccdimage.marccdimage
alias of
MarccdImage
fabio.numpyimage
Module
Generic numpy file reader for FabIO
- class fabio.numpyimage.NumpyImage(data=None, header=None)
Bases:
FabioImage
FabIO image class for Images for numpy array dumps
Source: http://docs.scipy.org/doc/numpy/neps/npy-format.html
Format Specification: Version 1.0:
The first 6 bytes are a magic string: exactly “x93NUMPY”. The next 1 byte is an unsigned byte: the major version number of the file format, e.g. x01. The next 1 byte is an unsigned byte: the minor version number of the file format, e.g. x00. Note: the version of the file format is not tied to the version of the numpy package. The next 2 bytes form a little-endian unsigned short int: the length of the header data HEADER_LEN. The next HEADER_LEN bytes form the header data describing the array’s format. It is an ASCII string which contains a Python literal expression of a dictionary. It is terminated by a newline (‘n’) and padded with spaces (‘x20’) to make the total length of the magic string + 4 + HEADER_LEN be evenly divisible by 16 for alignment purposes. The dictionary contains three keys: “descr” : dtype.descr An object that can be passed as an argument to the numpy.dtype() constructor to create the array’s dtype. “fortran_order” : bool Whether the array data is Fortran-contiguous or not. Since Fortran-contiguous arrays are a common form of non-C-contiguity, we allow them to be written directly to disk for efficiency. “shape” : tuple of int The shape of the array. For repeatability and readability, this dictionary is formatted using pprint.pformat() so the keys are in alphabetic order. Following the header comes the array data. If the dtype contains Python objects (i.e. dtype.hasobject is True), then the data is a Python pickle of the array. Otherwise the data is the contiguous (either C- or Fortran-, depending on fortran_order) bytes of the array. Consumers can figure out the number of bytes by multiplying the number of elements given by the shape (noting that shape=() means there is 1 element) by dtype.itemsize.
Format Specification: Version 2.0:
The version 1.0 format only allowed the array header to have a total size of 65535 bytes. This can be exceeded by structured arrays with a large number of columns. The version 2.0 format extends the header size to 4 GiB. numpy.save will automatically save in 2.0 format if the data requires it, else it will always use the more compatible 1.0 format. The description of the fourth element of the header therefore has become: The next 4 bytes form a little-endian unsigned int: the length of the header data HEADER_LEN.
- DEFAULT_EXTENSIONS = ['npy']
- DESCRIPTION = 'Numpy array file format'
- getframe(num)
returns the frame numbered ‘num’ in the stack if applicable
- next()
returns the next frame in the series as a fabioimage
- previous()
returns the previous frame in the series as a fabioimage
- read(fname, frame=None)
Try to read image
- Parameters:
fname – name of the file
- slice_dataset(frame=None)
- write(fname)
Try to write image
- Parameters:
fname – name of the file
- fabio.numpyimage.numpyimage
alias of
NumpyImage
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:
FabioImage
Oxford Diffraction Sapphire 3 images reader/writer class
Note: We assume the binary format is alway little-endian, is this True ?
- DEFAULT_EXTENSIONS = ['img']
- DESCRIPTION = 'Oxford Diffraction Sapphire 3 file format'
- static checkData(data=None)
- dec_TY5(stream)
Attempt to decode TY5 compression scheme
- Parameters:
stream – input stream
- Returns:
1D array with data
- 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
- class fabio.OXDimage.Section(size, dictHeader)
Bases:
object
Small 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
- class fabio.pilatusimage.PilatusImage(*args, **kwds)
Bases:
TifImage
Read in Pilatus format, also pilatus images, including header info
- DEFAULT_EXTENSIONS = ['tif', 'tiff']
- DESCRIPTION = 'Pilatus file format based on Tiff'
- class fabio.pilatusimage.PilatusTiffFrame(data, tiff_header, pilatus_header)
Bases:
TiffFrame
Frame container for TIFF format generated by a Pilatus detector
- fabio.pilatusimage.pilatusimage
alias of
PilatusImage
fabio.pixiimage
Module
File format to read images from PiXIrad PCDs manufactured by Pixirad Imaging Counters SRL (http://www.pixirad.com/)
Author: Jon Wright, ESRF.
- class fabio.pixiimage.PixiImage(data=None, header=None)
Bases:
FabioImage
- DEFAULT_EXTENSIONS = []
- DESCRIPTION = 'Pixi file format'
- 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)
To be overridden - fill in self.header and self.data
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: MIT
- class fabio.pnmimage.PnmImage(*arg, **kwargs)
Bases:
FabioImage
- DEFAULT_EXTENSIONS = ['pnm', 'pgm', 'pbm']
- DESCRIPTION = 'PNM file format'
- P1dec(buf, bytecode)
- P2dec(buf, bytecode)
- P3dec(buf, bytecode)
- P4dec(buf, bytecode)
- P5dec(buf, bytecode)
- P6dec(buf, bytecode)
- P7dec(buf, bytecode)
- static check_data(data=None)
Empty for fabioimage but may be populated by others classes, especially for format accepting only integers
- Parameters:
data – array like
- Returns:
numpy array or 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(fname)
try to write image. For now, limited to :param fname: name of the file
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:
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.
- DEFAULT_EXTENSIONS = ['img']
- DESCRIPTION = 'Rigaku RAXIS file format'
- 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.raxisimage.raxisimage
alias of
RaxisImage
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)
- class fabio.tifimage.TifImage(*args, **kwds)
Bases:
FabioImage
Images in TIF format Wraps TiffIO
- DEFAULT_EXTENSIONS = ['tif', 'tiff']
- DESCRIPTION = 'Tagged image file format'
- close()
- getframe(num)
Returns the frame num.
This frame is not cached on the image structure.
- read(fname, frame=None)
Wrapper for TiffIO.
- write(fname)
Overrides the FabioImage.write method and provides a simple TIFF image writer.
- Parameters:
fname (str) – name of the file to save the image to
- class fabio.tifimage.TiffFrame(data, tiff_header)
Bases:
FabioFrame
Frame container for TIFF format
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:
FabioImage
Read the XSDataImage XML File data format
- DEFAULT_EXTENSIONS = ['xml', 'xsd']
- DESCRIPTION = 'XSDataImage XML file format'
- read(fname, frame=None)
fabio.compression
Module
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…
- Parameters:
inp (str) – input format (like “cbfimage”)
outp (str) – output format (like “cbfimage”)
data (numpy.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
- Parameters:
inp (str) – input format (like “cbfimage”)
outp (str) – output format (like “cbfimage”)
header (dict) – the actual set of headers to be transformed
fabio.datIO
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, ESRF
- class fabio.datIO.columnfile(data=None, clabels=None, rlabels=None, fname=None)
Bases:
fabiodata
Concrete fabiodata class
- read(fname, frame=None)
To be overridden by format specific subclasses
- class fabio.datIO.fabiodata(data=None, clabels=None, rlabels=None, fname=None)
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)
To be overridden by format specific subclasses
fabio.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=<class '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