FabIO Package¶
fabio
Package¶
FabIO module
-
fabio.
benchmarks
()¶ Run the benchmarks
-
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.
FabioImage
(data=None, header=None)¶ Bases:
object
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.
-
bpp
¶ Getter for bpp: data superseeds _bpp
-
bytecode
¶ Getter for bpp: data superseeds _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
-
static
check_header
(header=None)¶ Empty for fabioimage but may be populated by others classes
Parameters: header – dict like object Returns: Ordered dict
-
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
-
dim1
¶ Getter for dim1: data superseeds _dim1
-
dim2
¶ Getter for dim2: data superseeds _dim2
-
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: fabio.fabioimage.FabioImage
-
get_bpp
()¶ Getter for bpp: data superseeds _bpp
-
get_bytecode
()¶ Getter for bpp: data superseeds _bytecode
-
get_dim1
()¶ Getter for dim1: data superseeds _dim1
-
get_dim2
()¶ Getter for dim2: data superseeds _dim2
-
get_header_keys
()¶
-
getclassname
()¶ Retrieves the name of the class :return: the name of the class
-
getframe
(num)¶ returns the file numbered ‘num’ in the series as a fabioimage
-
getheader
()¶ returns self.header
-
getmax
()¶ Find max value in self.data, caching for the future
-
getmean
()¶ return the mean
-
getmin
()¶ Find min value in self.data, caching for the future
-
getstddev
()¶ return the standard deviation
-
header_keys
¶
-
incomplete_file
¶ Returns true if the readed file is not complete.
Return type: bool
-
integrate_area
(coords)¶ Sums up a region of interest if len(coords) == 4 -> convert coords to slices if len(coords) == 2 -> use as slices floor -> ? removed as unused in the function.
-
load
(*arg, **kwarg)¶ Wrapper for read
-
make_slice
(coords)¶ Convert a len(4) set of coords into a len(2) tuple (pair) of slice objects the latter are immutable, meaning the roi can be cached
-
next
()¶ Returns the next file in the series as a fabioimage
Raises: IOError – When there is no next file in the series.
-
previous
()¶ returns the previous file in the series as a fabioimage
-
read
(filename, frame=None)¶ To be overridden - fill in self.header and self.data
-
readROI
(filename, frame=None, coords=None)¶ Method reading Region of Interest. This implementation is the trivial one, just doing read and crop
-
readheader
(filename)¶ Call the _readheader function...
-
rebin
(x_rebin_fact, y_rebin_fact, keep_I=True)¶ Rebin the data and adjust dims :param int x_rebin_fact: x binning factor :param int y_rebin_fact: y binning factor :param bool keep_I: shall the signal increase ?
-
registry
= { "edfimage": "<class 'fabio.edfimage.EdfImage'>", "adscimage": "<class 'fabio.adscimage.AdscImage'>", "tifimage": "<class 'fabio.tifimage.TifImage'>", "marccdimage": "<class 'fabio.marccdimage.MarccdImage'>", "mar345image": "<class 'fabio.mar345image.Mar345Image'>", "fit2dmaskimage": "<class 'fabio.fit2dmaskimage.Fit2dMaskImage'>", "brukerimage": "<class 'fabio.brukerimage.BrukerImage'>", "bruker100image": "<class 'fabio.bruker100image.Bruker100Image'>", "pnmimage": "<class 'fabio.pnmimage.PnmImage'>", "geimage": "<class 'fabio.GEimage.GeImage'>", "oxdimage": "<class 'fabio.OXDimage.OxdImage'>", "dm3image": "<class 'fabio.dm3image.Dm3Image'>", "hipicimage": "<class 'fabio.HiPiCimage.HipicImage'>", "pilatusimage": "<class 'fabio.pilatusimage.PilatusImage'>", "fit2dspreadsheetimage": "<class 'fabio.fit2dspreadsheetimage.Fit2dSpreadsheetImage'>", "kcdimage": "<class 'fabio.kcdimage.KcdImage'>", "cbfimage": "<class 'fabio.cbfimage.CbfImage'>", "xsdimage": "<class 'fabio.xsdimage.XsdImage'>", "binaryimage": "<class 'fabio.binaryimage.BinaryImage'>", "pixiimage": "<class 'fabio.pixiimage.PixiImage'>", "raxisimage": "<class 'fabio.raxisimage.RaxisImage'>", "numpyimage": "<class 'fabio.numpyimage.NumpyImage'>", "eigerimage": "<class 'fabio.eigerimage.EigerImage'>", "hdf5image": "<class 'fabio.hdf5image.Hdf5Image'>", "fit2dimage": "<class 'fabio.fit2dimage.Fit2dImage'>", "speimage": "<class 'fabio.speimage.SpeImage'>", "jpegimage": "<class 'fabio.jpegimage.JpegImage'>", "jpeg2kimage": "<class 'fabio.jpeg2kimage.Jpeg2KImage'>", "mpaimage": "<class 'fabio.mpaimage.MpaImage'>" }¶
-
resetvals
()¶ Reset cache - call on changing data
-
save
(fname)¶ wrapper for write
-
set_bpp
(value)¶ Setter for bpp
-
set_bytecode
(value)¶ Setter for bpp
-
set_dim1
(value)¶ Setter for dim1
-
set_dim2
(value)¶ Setter for dim2
-
set_header_keys
(value)¶
-
toPIL16
(filename=None)¶ Convert to Python Imaging Library 16 bit greyscale image
-
update_header
(**kwds)¶ update the header entries by default pass in a dict of key, values.
-
write
(fname)¶ To be overwritten - write the file
-
-
class
fabio.fabioimage.
FabioMeta
(name, bases, dct)¶ Bases:
type
Metaclass used to register all image classes inheriting from fabioImage
-
DEFAULT_EXTENTIONS
¶ Compatibility with the wrong typo.
Note
Will be marked as deprecated for the following version 0.7.
-
-
fabio.fabioimage.
fabioimage
¶ alias of
FabioImage
fabio.fabioutils
Module¶
General purpose utilities functions for fabio
-
class
fabio.fabioutils.
BZ2File
(name, mode='r', buffering=0, compresslevel=9)¶ Bases:
bz2.BZ2File
Wrapper with lock
-
getSize
()¶
-
setSize
(value)¶
-
size
¶
-
-
class
fabio.fabioutils.
BytesIO
(data, fname=None, mode='r')¶ Bases:
StringIO.StringIO
just an interface providing the name and mode property to a BytesIO
BugFix for MacOSX mainly
-
getSize
()¶
-
setSize
(size)¶
-
size
¶
-
-
class
fabio.fabioutils.
DebugSemaphore
(*arg, **kwarg)¶ Bases:
threading._Semaphore
threading.Semaphore like class with helper for fighting dead-locks
-
acquire
(*arg, **kwarg)¶
-
blocked
= []¶
-
release
(*arg, **kwarg)¶
-
write_lock
= <threading._Semaphore object>¶
-
-
class
fabio.fabioutils.
File
(name, mode='rb', buffering=0, temporary=False)¶ Bases:
file
wrapper for “file” with locking
-
close
()¶
-
getSize
()¶
-
setSize
(size)¶
-
size
¶
-
-
class
fabio.fabioutils.
FilenameObject
(stem=None, num=None, directory=None, format_=None, extension=None, postnum=None, digits=4, filename=None)¶ Bases:
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:
gzip.GzipFile
Just a wrapper for gzip.GzipFile providing the correct seek capabilities for python 2.5
-
measure_size
()¶
-
-
exception
fabio.fabioutils.
NotGoodReader
¶ Bases:
exceptions.RuntimeError
The reader used is probably not the good one
-
class
fabio.fabioutils.
OrderedDict
(*args, **kwds)¶ Bases:
fabio.third_party._local.ordereddict.OrderedDict
Ordered dictionary with pretty print
-
class
fabio.fabioutils.
UnknownCompressedFile
(name, mode='rb', buffering=0)¶ Bases:
fabio.fabioutils.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.
deprecated
(func)¶ used to deprecate a function/method: prints a lot of warning messages to enforce the modification of the code
-
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.file_series
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.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)¶ Much like the others, but created from a string filename
-
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 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)¶ 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:
fabio.file_series.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
-
fabio.openimage.
do_magic
(byts, filename)¶ Try to interpret the bytes starting the file as a magic number
-
fabio.openimage.
openheader
(filename)¶ return only the header
-
fabio.openimage.
openimage
(filename, frame=None)¶ Try to open an image
fabio.adscimage
Module¶
- Authors: Henning O. Sorensen & Erik Knudsen
- Center for Fundamental Research: Metal Structures in Four Dimensions Risoe National Laboratory Frederiksborgvej 399 DK-4000 Roskilde email:erik.knudsen@risoe.dk
- mods for fabio by JPW
-
class
fabio.adscimage.
AdscImage
(*args, **kwargs)¶ Bases:
fabio.fabioimage.FabioImage
Read an image in ADSC format (quite similar to edf?)
-
DEFAULT_EXTENSIONS
= ['img']¶
-
DESCRIPTION
= 'ADSC format (from Area Detector Systems Corporation)'¶
-
read
(fname, frame=None)¶ read in the file
-
swap_needed
()¶
-
write
(fname)¶ Write adsc format
-
fabio.binaryimage
Module¶
Authors: Gael Goret, Jerome Kieffer, ESRF, France
- Emails: gael.goret@esrf.fr, jerome.kieffer@esrf.fr
- Brian Richard Pauw <brian@stack.nl>
Binary files images are simple none-compressed 2D images only defined by their : data-type, dimensions, byte order and offset
This simple library has been made for manipulating exotic/unknown files format.
-
class
fabio.binaryimage.
BinaryImage
(*args, **kwargs)¶ Bases:
fabio.fabioimage.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 short or long endian (“<” or “>”)
-
static
swap_needed
(endian)¶ Decide if we need to byteswap
-
write
(fname)¶
-
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:
fabio.brukerimage.BrukerImage
-
DEFAULT_EXTENSIONS
= ['sfrm']¶
-
DESCRIPTION
= 'SFRM File format used by Bruker detectors (version 100)'¶
-
bpp_to_numpy
= {1: <type 'numpy.uint8'>, 2: <type 'numpy.uint16'>, 4: <type 'numpy.int32'>}¶
-
gen_header
()¶ Generate headers (with some magic and guesses) format is Bruker100
-
gen_overflow
()¶ Generate an overflow table, including the underflow, marked as 65535 .
-
gen_underflow100
()¶ Generate an underflow table
-
overflows_one_byte
()¶ Generate one-byte overflow table
-
overflows_two_byte
()¶ Generate two byte overflow table
-
read
(fname, frame=None)¶ data is stored in three blocks: data (uint8), overflow (uint32), underflow (int32). The blocks are zero paded to a multiple of 16 bits
-
toPIL16
(filename=None)¶
-
underflows
()¶ Generate underflow table
-
version
= 100¶
-
write
(fname)¶ Write a bruker image
-
-
fabio.bruker100image.
bruker100image
¶ alias of
Bruker100Image
fabio.brukerimage
Module¶
- Authors: Henning O. Sorensen & Erik Knudsen
- Center for Fundamental Research: Metal Structures in Four Dimensions Risoe National Laboratory Frederiksborgvej 399 DK-4000 Roskilde email:erik.knudsen@risoe.dk
- Based on: openbruker,readbruker, readbrukerheader functions in the opendata
- module of ImageD11 written by Jon Wright, ESRF, Grenoble, France
Writer by Jérôme Kieffer, ESRF, Grenoble, France
-
class
fabio.brukerimage.
BrukerImage
(data=None, header=None)¶ Bases:
fabio.fabioimage.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: <type 'numpy.uint8'>, 2: <type 'numpy.uint16'>, 4: <type 'numpy.uint32'>}¶
-
calc_bpp
(data=None, max_entry=4096)¶ Calculate the number of byte per pixel to get an optimal overflow table.
Returns: byte per pixel
-
gen_header
()¶ Generate headers (with some magic and guesses) :param format can be 86 or 100
-
gen_overflow
()¶ Generate an overflow table
-
read
(fname, frame=None)¶ Read in and unpack the pixels (including overflow table
-
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
= '--CIF-BINARY-FORMAT-SECTION--'¶
-
BLANK
= [' ', '\t', '\r', '\n', '\r\n', '\n\r']¶
-
DATA
= 'data_'¶
-
DOUBLE_QUOTE
= '"'¶
-
EOL
= ['\r', '\n', '\r\n', '\n\r']¶
-
GLOBAL
= 'global_'¶
-
HASH
= '#'¶
-
LOOP
= 'loop_'¶
-
static
LoopHasKey
(loop, key)¶ Returns True if the key (string) exist in the array called loop
-
QUESTIONMARK
= '?'¶
-
SAVE
= 'save_'¶
-
SEMICOLUMN
= ';'¶
-
SINGLE_QUOTE
= "'"¶
-
START_COMMENT
= ("'", '"')¶
-
STOP
= 'stop_'¶
-
UNDERSCORE
= '_'¶
-
exists
(sKey)¶ Check if the key exists in the CIF and is non empty.
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
-
i
= '\t'¶
-
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
(key, default=None)¶
-
popitem
(key, default=None)¶
-
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:
fabio.fabioimage.FabioImage
Read the Cif Binary File data format
-
BINARAY_SECTION
= '--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
= '\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 are correct position Returns: raw compressed stream
-
write
(fname)¶ write the file in CBF format :param str fname: name of the file
-
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:
fabio.fabioimage.FabioImage
Read and try to write the dm3 data format
-
DEFAULT_EXTENSIONS
= ['dm3']¶
-
DESCRIPTION
= 'Digital Micrograph DM3 file format'¶
-
read
(fname, frame=None)¶
-
read_data
()¶
-
read_tag_entry
()¶
-
read_tag_group
()¶
-
read_tag_type
()¶
-
readbytes
(bytes_to_read, format, swap=True)¶
-
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.
EdfImage
(data=None, header=None, frames=None)¶ Bases:
fabio.fabioimage.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)¶ Method used add a frame to an EDF file :param frame: frame to append to edf image :type frame: instance of Frame
-
bpp
¶
-
bytecode
¶
-
static
check_header
(header=None)¶ Empty for FabioImage but may be populated by others classes
-
data
¶ property: data of EDF file
-
delData
()¶ deleter for edf Data
-
delHeader
()¶ Deleter for edf header
-
deleteFrame
(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.
-
dim1
¶
-
dim2
¶
-
dims
¶
-
fastReadData
(filename=None)¶ This is a special method that will read and return the data from another file ... The aim is performances, ... but only supports uncompressed files.
Returns: data from another file using positions from current EdfImage
-
fastReadROI
(filename, coords=None)¶ Method reading Region of Interest of another file based on metadata available in current EdfImage. The aim is performances, ... but only supports uncompressed files.
Returns: ROI-data from another file using positions from current EdfImage Return type: numpy 2darray
-
getBpp
()¶
-
getByteCode
()¶
-
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
-
header
¶ property: header of EDF file
-
incomplete_data
¶
-
incomplete_file
¶ Returns true if the file is not complete.
Return type: bool
-
isIncompleteData
()¶
-
next
()¶ Returns the next file in the series as a fabioimage
Raises: IOError – When there is no next file or image in the series.
-
nframes
¶ Getter for number of frames
-
previous
()¶ returns the previous file in the series as a FabioImage
-
read
(fname, frame=None)¶ - Read in header into self.header and
- the data into self.data
-
setBpp
(_iVal)¶
-
setByteCode
(_iVal)¶
-
setData
(_data)¶ Enforces the propagation of the data to the list of frames :param _data: numpy array representing data
-
setDim1
(_iVal)¶
-
setDim2
(_iVal)¶
-
setHeader
(_dictHeader)¶ Enforces the propagation of the header to the list of frames
-
setNbFrames
(val)¶ Setter for number of frames ... should do nothing. Here just to avoid bugs
-
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”
-
-
class
fabio.edfimage.
Frame
(data=None, header=None, number=None)¶ 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
()¶
-
getData
()¶ Unpack a binary blob according to the specification given in the header
Returns: dataset as numpy.ndarray
-
getEdfBlock
(force_type=None, fit2dMode=False)¶ Parameters: - force_type (string or numpy.dtype) – type of the dataset to be enforced like “float64” or “uint16”
- fit2dMode (boolean) – enforce compatibility with fit2d and starts counting number of images at 1
Returns: ascii header block + binary data block
Return type: python bytes with the concatenation of the ascii header and the binary data block
-
parseheader
(block)¶ Parse the header in some EDF format from an already open file
Parameters: block (str) – string representing the header block. Returns: size of the binary blob
-
setByteCode
(_iVal)¶
-
setData
(npa=None)¶ Setter for data in edf frame
-
swap_needed
()¶ Decide if we need to byteswap
-
-
exception
fabio.edfimage.
MalformedHeaderError
¶ Bases:
exceptions.IOError
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:
- https://github.com/nexusformat/HDF5-External-Filter-Plugins/tree/master/LZ4
- https://github.com/kiyo-masui/bitshuffle
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:
fabio.fabioimage.FabioImage
FabIO image class for Images from Eiger data files (HDF5)
-
DEFAULT_EXTENSIONS
= ['h5']¶
-
DESCRIPTION
= 'Eiger data files based on HDF5'¶
-
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 :param fname: name of the file
-
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:
fabio.fabioimage.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.fit2dmaskimage
Module¶
Author: Andy Hammersley, ESRF Translation into python/fabio: Jon Wright, ESRF. Writer: Jérôme Kieffer
-
class
fabio.fit2dmaskimage.
Fit2dMaskImage
(data=None, header=None)¶ Bases:
fabio.fabioimage.FabioImage
Read and try to write Andy Hammersley’s mask format
-
DEFAULT_EXTENSIONS
= ['msk']¶
-
DESCRIPTION
= 'Fit2d mask file format'¶
-
static
check_data
(data=None)¶
-
read
(fname, frame=None)¶ - Read in header into self.header and
- the data into self.data
-
write
(fname)¶ Try to write a file
-
-
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:
fabio.fabioimage.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¶
-
class
fabio.GEimage.
GeImage
(data=None, header=None)¶ Bases:
fabio.fabioimage.FabioImage
-
DEFAULT_EXTENSIONS
= []¶
-
DESCRIPTION
= 'GE a-Si Angio detector 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)¶ Read in header into self.header and the data into self.data
-
-
fabio.GEimage.
demo
()¶
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.
Hdf5Image
(*arg, **kwargs)¶ Bases:
fabio.fabioimage.FabioImage
FabIO image class for Images from an HDF file
filename::dataset
-
DEFAULT_EXTENSIONS
= ['h5']¶
-
DESCRIPTION
= 'Hierarchical Data Format HDF5 flat reader'¶
-
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:
fabio.fabioimage.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:
fabio.fabioimage.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:
fabio.fabioimage.FabioImage
-
DEFAULT_EXTENSIONS
= ['mar2300']¶
-
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
-
class
fabio.mrcimage.
MrcImage
(data=None, header=None)¶ Bases:
fabio.fabioimage.FabioImage
FabIO image class for Images from a mrc image stack
-
DEFAULT_EXTENSIONS
= ['mrc']¶
-
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:
fabio.tifimage.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:
fabio.fabioimage.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:
fabio.fabioimage.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:
fabio.tifimage.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:
fabio.tifimage.TiffFrame
Frame container for TIFF format generated by a Pilatus detector
-
header
¶ Default header exposed by fabio
-
-
fabio.pilatusimage.
pilatusimage
¶ alias of
PilatusImage
fabio.pixiimage
Module¶
Author: Jon Wright, ESRF.
-
class
fabio.pixiimage.
PixiImage
(data=None, header=None)¶ Bases:
fabio.fabioimage.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)¶
-
-
fabio.pixiimage.
demo
(fname)¶
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:
fabio.fabioimage.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)¶
-
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:
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.
-
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)
License: MIT
-
class
fabio.tifimage.
TifImage
(*args, **kwds)¶ Bases:
fabio.fabioimage.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.
-
fabio.xsdimage
Module¶
- Authors: Jérôme Kieffer, ESRF
- email:jerome.kieffer@esrf.fr
XSDimge are XML files containing numpy arrays
-
class
fabio.xsdimage.
XsdImage
(data=None, header=None, fname=None)¶ Bases:
fabio.fabioimage.FabioImage
Read the XSDataImage XML File data format
-
DEFAULT_EXTENSIONS
= ['xml', 'xsd']¶
-
DESCRIPTION
= 'XSDataImage XML file format'¶
-
read
(fname, frame=None)¶
-
fabio.compression
Module¶
Compression and decompression algorithm for various formats
- Authors: Jérôme Kieffer, ESRF
- email:jerome.kieffer@esrf.fr
-
class
fabio.compression.
ExternalCompressors
¶ Bases:
object
Class to handle lazy discovery of external compression programs
-
COMMANDS
= {'.bz2': ['bzip2-dcf'], '.gz': ['gzip', '-dcf']}¶
-
-
fabio.compression.
compByteOffset
(data)¶ Compress a dataset into a string using the byte_offet algorithm
Parameters: data – ndarray Returns: string/bytes with compressed data test = numpy.array([0,1,2,127,0,1,2,128,0,1,2,32767,0,1,2,32768,0,1,2,2147483647,0,1,2,2147483648,0,1,2,128,129,130,32767,32768,128,129,130,32768,2147483647,2147483648])
-
fabio.compression.
compByteOffset_cython
(data)¶ Compress a dataset into a string using the byte_offet algorithm
Parameters: data – ndarray Returns: string/bytes with compressed data test = numpy.array([0,1,2,127,0,1,2,128,0,1,2,32767,0,1,2,32768,0,1,2,2147483647,0,1,2,2147483648,0,1,2,128,129,130,32767,32768,128,129,130,32768,2147483647,2147483648])
-
fabio.compression.
compByteOffset_numpy
(data)¶ Compress a dataset into a string using the byte_offet algorithm
Parameters: data – ndarray Returns: string/bytes with compressed data test = numpy.array([0,1,2,127,0,1,2,128,0,1,2,32767,0,1,2,32768,0,1,2,2147483647,0,1,2,2147483648,0,1,2,128,129,130,32767,32768,128,129,130,32768,2147483647,2147483648])
-
fabio.compression.
compPCK
(data)¶ Modified CCP4 pck compressor used in MAR345 images
Parameters: data – numpy.ndarray (square array) Returns: compressed stream
-
fabio.compression.
compTY1
(data)¶ Modified byte offset compressor used in Oxford Diffraction images
Parameters: data – numpy.ndarray with the input data (integers!) Returns: 3-tuple of strings: raw_8,raw_16,raw_32 containing raw data with integer of the given size
-
fabio.compression.
decByteOffset
(stream, size=None, dtype='int64')¶ - Analyze a stream of char with any length of exception:
- 2, 4, or 8 bytes integers
Parameters: - stream – string representing the compressed data
- size – the size of the output array (of longInts)
Returns: 1D-ndarray
-
fabio.compression.
decByteOffset_cython
(stream, size=None, dtype='int64')¶ - Analyze a stream of char with any length of exception:
- 2, 4, or 8 bytes integers
Parameters: - stream – string representing the compressed data
- size – the size of the output array (of longInts)
Returns: 1D-ndarray
-
fabio.compression.
decByteOffset_numpy
(stream, size=None, dtype='int64')¶ - Analyze a stream of char with any length of exception:
- 2, 4, or 8 bytes integers
Parameters: - stream – string representing the compressed data
- size – the size of the output array (of longInts)
Returns: 1D-ndarray
-
fabio.compression.
decBzip2
(stream)¶ Decompress a chunk of data using the bzip2 algorithm from Python
-
fabio.compression.
decGzip
(stream)¶ Decompress a chunk of data using the gzip algorithm from system or from Python
Parameters: stream – compressed data Returns: uncompressed stream
-
fabio.compression.
decKM4CCD
(raw_8, raw_16=None, raw_32=None)¶ Modified byte offset decompressor used in Oxford Diffraction images
Note: Always expect little endian data on the disk
Parameters: - raw_8 – strings containing raw data with integer 8 bits
- raw_16 – strings containing raw data with integer 16 bits
- raw_32 – strings containing raw data with integer 32 bits
Returns: numpy.ndarray
-
fabio.compression.
decPCK
(stream, dim1=None, dim2=None, overflowPix=None, version=None, normal_start=None, swap_needed=None)¶ Modified CCP4 pck decompressor used in MAR345 images
Parameters: - raw – input string (bytes in python3)
- dim1,dim2 – optional parameters size
- overflowPix – optional parameters: number of overflowed pixels
- version – PCK version 1 or 2
- normal_start – position of the normal value section (can be auto-guessed)
- swap_needed – set to True when reading data from a foreign endianness (little on big or big on little)
Returns: ndarray of 2D with the right size
-
fabio.compression.
decTY1
(raw_8, raw_16=None, raw_32=None)¶ Modified byte offset decompressor used in Oxford Diffraction images
Note: Always expect little endian data on the disk
Parameters: - raw_8 – strings containing raw data with integer 8 bits
- raw_16 – strings containing raw data with integer 16 bits
- raw_32 – strings containing raw data with integer 32 bits
Returns: numpy.ndarray
-
fabio.compression.
decZlib
(stream)¶ Decompress a chunk of data using the zlib algorithm from Python
-
fabio.compression.
endianness
()¶ Return the native endianness of the system
-
fabio.compression.
is_incomplete_gz_block_exception
(exception)¶ True if the exception looks to be generated when a GZ block is incomplete.
Return type: bool
-
fabio.compression.
md5sum
(blob)¶ returns the md5sum of an object...
fabio.converters
Module¶
Converter module.
This is for the moment empty (populated only with almost pass through anonymous functions) but aims to be populated with more sofisticated translators...
-
fabio.converters.
convert_data
(inp, outp, data)¶ Return data converted to the output format ... over-simplistic implementation for the moment...
Parameters:
-
fabio.converters.
convert_data_integer
(data)¶ convert data to integer
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:
fabio.datIO.fabiodata
Concrete fabiodata class
-
read
(fname, frame=None)¶
-
-
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=<type 'numpy.uint16'>)¶ Reads in a bytestream from a file (which may be a string indicating a filename, or an already opened file (should be “rb”)) offset is the position (in bytes) where the pixel data start nbytespp = number of bytes per pixel type can be int or float (4 bytes pp) or double (8 bytes pp) signed: normally signed data ‘y’, but ‘n’ to try to get back the right numbers when unsigned data are converted to signed (python once had no unsigned numeric types.) swap, normally do not bother, but ‘y’ to swap bytes typeout is the numpy type to output, normally uint16, but more if overflows occurred x and y are the pixel dimensions
TODO : Read in regions of interest
PLEASE LEAVE THE STRANGE INTERFACE ALONE - IT IS USEFUL FOR THE BRUKER FORMAT