FabIO is an I/O library for images produced by 2D X-ray detectors and written in Python.
FabIO support images detectors from a dozen of companies (including Mar, Dectris, ADSC, Hamamatsu, Oxford, …),
for a total of 20 different file formats (like CBF, EDF, TIFF, …) and offers an unified interface to their
headers (as a python dictionary) and datasets (as a numpy ndarray of integers or floats)
FabIO is expected to handle gzip and bzip2 compressed files transparently.
Following a query about the performance of reading compressed data, some
benchmarking details have been collected at fabio_compressed_speed.
This means that when your python was configured and built you needed the
bzip and gzip modules to be present (eg libbz2-dev package for ubuntu)
Using fabio in your own python programs
Have a base class for all our 2D diffraction greyscale images.
This consists of a 2D array (numpy ndarray)
and a python dictionary (actually an ordered dict) of header information in (string key, string value) pairs.
Needs a name which will not to be confused with an RGB color image.
data -> 2D array
header -> ordered dictionary
rows, columns, dim1, dim2 -> data.shape (properties determined on the fly)
header_keys -> property for list(header.keys()), formerly used to retain the order of the header
bytecode -> data.typecode() (property)
m, minval, maxval, stddev -> image statistics, could add others, eg roi[slice]
Class methods (functions):
integrate_area() -> return sum(self.data) within slice
rebin(fact) -> rebins data, adjusts dims
toPIL16() -> returns a PILimage
getheader() -> returns self.header
resetvals() -> resets the statistics
getmean() -> (computes) returns self.m
getmin() -> (computes) returns self.minval
getmax() -> (computes) returns self.maxval
getstddev() -> (computes) returns self.stddev
read() -> read image from file [or stream, or shared memory]
write() -> write image to file [or stream, or shared memory]
readheader() -> read only the header [much faster for scanning files]
Each individual file format would then inherit all the functionality of this class and just make new read and write methods.
There are also fileseries related methods (next(), previous(), …) which returns a FabioImage instance of the next/previous frame in a fileserie
possibility for using on-the-fly external compression - i.e. if files are
stored as something as .gz, .bz2 etc could decompress them, using an external
compression mechanism (if available). This is present in fabian but requires
that images are edfs.
Known file formats
KcdImage: Nonius KappaCCD diffractometer
MarccdImage (fileformat derived from Tiff)
Mar345Image imaging plate with PCK compression
CbfImage (implements a fast byte offset de/compression scheme in python/cython)