### Navigation

- index
- modules |
- previous |
- FabIO 0.1.3 documentation »

# FabIO Package

## `fabio` Package

FabIO module

## `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)

  `add`(other)

    Add another Image - warning, does not clip to 16 bit images by default

  static `checkData`(data=None)

    Empty for fabioimage but may be populated by others classes, especially for format accepting only integers

  static `checkHeader`(header=None)

    Empty for fabioimage but may be populated by others classes

  `classname`

    Retrieves the name of the class :return: the name of the class

  `convert`(dest)

    Convert a fabioimage object into another fabioimage object (with possible conversions) :param dest: destination type “EDF”, “edfimage” or the class itself

  `getclassname`()

    Retrieves the name of the class :return: the name of the class

  `getframe`(num)

    returns the file numbered ‘num’ in the series as a fabioimage

  `getheader`()

    returns self.header

  `getmax`()

    Find max value in self.data, caching for the future

  `getmean`()

    return the mean

  `getmin`()

    Find min value in self.data, caching for the future

  `getstddev`()

    return the standard deviation

  `integrate_area`(coords)

    Sums up a region of interest if len(coords) == 4 -> convert coords to slices if len(coords) == 2 -> use as slices floor -> ? removed as unused in the function.

  `load`(*arg, **kwarg)

    Wrapper for read

  `make_slice`(coords)

    Convert a len(4) set of coords into a len(2) tuple (pair) of slice objects the latter are immutable, meaning the roi can be cached

  `next`()

    returns the next file in the series as a fabioimage

  `previous`()

    returns the previous file in the series as a fabioimage

  `read`(filename, frame=None)

    To be overridden - fill in self.header and self.data

  `readROI`(filename, frame=None, coords=None)

    Method reading Region of Interest. This implementation is the trivial one, just doing read and crop

  `readheader`(filename)

    Call the _readheader function...

  `rebin`(x_rebin_fact, y_rebin_fact, keep_I=True)

    Rebin the data and adjust dims :param x_rebin_fact: x binning factor :param y_rebin_fact: y binning factor :param keep_I: shall the signal increase ? :type x_rebin_fact: int :type y_rebin_fact: int :type keep_I: boolean

  `resetvals`()

    Reset cache - call on changing data

  `save`(fname)

    wrapper for write

  `toPIL16`(filename=None)

    Convert to Python Imaging Library 16 bit greyscale image

    FIXME - this should be handled by the libraries now

  `update_header`(**kwds)

    update the header entries by default pass in a dict of key, values.

  `write`(fname)

    To be overwritten - write the file

`fabio.fabioimage.``test`()

  check some basic fabioimage functionality

## `fabio.fabioutils` Module

General purpose utilities functions for fabio

class `fabio.fabioutils.``BZ2File`(name, mode='r', buffering=0, compresslevel=9)

  Bases: `bz2.BZ2File`

  Wrapper with lock

  `getSize`()
  `setSize`(value)
  `size`

class `fabio.fabioutils.``File`(name, mode='rb', buffering=0)

  Bases: `file`

  wrapper for “file” with locking

  `getSize`()
  `setSize`(size)
  `size`

class `fabio.fabioutils.``FilenameObject`(stem=None, num=None, directory=None, format=None, extension=None, postnum=None, digits=4, filename=None)

  Bases: `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 forgzip.GzipFile providing the correct seek capabilities for python 2.5

class `fabio.fabioutils.``StringIO`(data, fname=None, mode='r')

  Bases: `StringIO.StringIO`

  just an interface providing the name and mode property to a StringIO

  BugFix for MacOSX mainly

  `getSize`()
  `setSize`(size)
  `size`

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 modifaction of the code

`fabio.fabioutils.``extract_filenumber`(name)

  extract file number

`fabio.fabioutils.``getnum`(name)

  # try to figure out a file number # guess it starts at the back

`fabio.fabioutils.``isAscii`(name, listExcluded=None)

  Parameters:

  - name – string to check
  - listExcluded – list of char or string excluded.

  Returns: | True of False whether name is pure ascii or not

`fabio.fabioutils.``jump_filename`(name, num, padding=True)

  jump to number

`fabio.fabioutils.``next_filename`(name, padding=True)

  increment number

`fabio.fabioutils.``nice_int`(s)

  Workaround that int(‘1.0’) raises an exception

  Parameters: | s – string to be converted to integer

`fabio.fabioutils.``numstem`(name)

  cant see how to do without reversing strings Match 1 or more digits going backwards from the end of the string

`fabio.fabioutils.``pad`(mystr, pattern=' ', size=80)

  Performs the padding of the string to the right size with the right pattern

`fabio.fabioutils.``previous_filename`(name, padding=True)

  decrement number

`fabio.fabioutils.``toAscii`(name, excluded=None)

  Parameters:

  - name – string to check
  - excluded – tuple of char or string excluded (not list: they are mutable).

  Returns: | the name with all non valid char removed

## `fabio.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

`fabio.openimage.``do_magic`(byts)

  Try to interpret the bytes starting the file as a magic number

`fabio.openimage.``openheader`(filename)

  return only the header

`fabio.openimage.``openimage`(filename, frame=None)

  Try to open an image

## `fabio.adscimage` Module

Authors: Henning O. Sorensen & Erik Knudsen
  Center for Fundamental Research: Metal Structures in Four Dimensions Risoe National Laboratory Frederiksborgvej 399 DK-4000 Roskilde email:erik.knudsen@risoe.dk

- mods for fabio by JPW

class `fabio.adscimage.``adscimage`(*args, **kwargs)

  Bases: `fabio.fabioimage.fabioimage`

  Read an image in ADSC format (quite similar to edf?)

  `read`(fname, frame=None)

    read in the file

  `write`(fname)

    Write adsc format

`fabio.adscimage.``test`()

  testcase

## `fabio.binaryimage` Module

Authors: Gael Goret, Jerome Kieffer, ESRF, France Emails: gael.goret@esrf.fr, jerome.kieffer@esrf.fr

> Brian Richard Pauw <brian@stack.nl>

Binary files images are simple none-compressed 2D images only defined by their : data-type, dimensions, byte order and offset

This simple library has been made for manipulating exotic/unknown files format.

class `fabio.binaryimage.``binaryimage`(*args, **kwargs)

  Bases: `fabio.fabioimage.fabioimage`

  This simple library has been made for manipulating exotic/unknown files format.

  Binary files images are simple none-compressed 2D images only defined by their : data-type, dimensions, byte order and offset

  if offset is set to a negative value, the image is read using the last data but n data in the file, skipping any header.

  `estimate_offset_value`(fname, dim1, dim2, bytecode='int32')

    Estimates the size of a file

  `read`(fname, dim1, dim2, offset=0, bytecode='int32', endian='<')

    Read a binary image

    Parameters:

    - fname (string) – file name
    - dim1 – image dimensions (Fast index)
    - dim2 – image dimensions (Slow index)
    - offset – starting position of the data-block. If negative, starts at the end.
    - bytecode – can be “int8”,”int16”,”int32”,”int64”,”uint8”,”uint16”,”uint32”,”uint64”,”float32”,”float64”,...
    - endian – among short or long endian (“<” or “>”)

  static `swap_needed`(endian)

    Decide if we need to byteswap

  `write`(fname)

## `fabio.bruker100image` Module

class `fabio.bruker100image.``bruker100image`(data=None, header=None)

  Bases: `fabio.brukerimage.brukerimage`

  `read`(fname, frame=None)
  `toPIL16`(filename=None)

## `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.

  `HEADERS_KEYS` = ['FORMAT', 'VERSION', 'HDRBLKS', 'TYPE', 'SITE', 'MODEL', 'USER', 'SAMPLE', 'SETNAME', 'RUN', 'SAMPNUM', 'TITLE', 'NCOUNTS', 'NOVERFL', 'MINIMUM', 'MAXIMUM', 'NONTIME', 'NLATE', 'FILENAM', 'CREATED', 'CUMULAT', 'ELAPSDR', 'ELAPSDA', 'OSCILLA', 'NSTEPS', 'RANGE', 'START', 'INCREME', 'NUMBER', 'NFRAMES', 'ANGLES', 'NOVER64', 'NPIXELB', 'NROWS', 'NCOLS', 'WORDORD', 'LONGORD', 'TARGET', 'SOURCEK', 'SOURCEM', 'FILTER', 'CELL', 'MATRIX', 'LOWTEMP', 'TEMP', 'HITEMP', 'ZOOM', 'CENTER', 'DISTANC', 'TRAILER', 'COMPRES', 'LINEAR', 'PHD', 'PREAMP', 'CORRECT', 'WARPFIL', 'WAVELEN', 'MAXXY', 'AXIS', 'ENDING', 'DETPAR', 'LUT', 'DISPLIM', 'PROGRAM', 'ROTATE', 'BITMASK', 'OCTMASK', 'ESDCELL', 'DETTYPE', 'NEXP', 'CCDPARM', 'BIS', 'CHEM', 'MORPH', 'CCOLOR', 'CSIZE', 'DNSMET', 'DARK', 'AUTORNG', 'ZEROADJ', 'XTRANS', 'HKL&XY', 'AXES2', 'ENDING2', 'FILTER2', 'LEPTOS', 'CFR']
  `SPACER` = '\x1a\x04'
  `basic_translate`(fname=None)

    Does some basic population of the headers so that the writing is possible

  `bpp_to_numpy` = {1: <type 'numpy.uint8'>, 2: <type 'numpy.uint16'>, 4: <type 'numpy.uint32'>}
  `calc_bpp`(data=None, max_entry=4096)

    Calculate the number of byte per pixel to get an optimal overflow table.

    Returns: | byte per pixel

  `gen_header`()

    Generate headers (with some magic and guesses) :param format can be 86 or 100

  `gen_overflow`()

    Generate an overflow table

  `read`(fname, frame=None)

    Read in and unpack the pixels (including overflow table

  `write`(fname)

    Write a bruker image

`fabio.brukerimage.``test`()

  a testcase

## `fabio.cbfimage` Module

Authors: Jérôme Kieffer, ESRF
  email:jerome.kieffer@esrf.fr

Cif Binary Files images are 2D images written by the Pilatus detector and others. They use a modified (simplified) byte-offset algorithm.

CIF is a library for manipulating Crystallographic information files and tries to conform to the specification of the IUCR

class `fabio.cbfimage.``CIF`(_strFilename=None)

  Bases: `dict`

  This is the CIF class, it represents the CIF dictionary; and as a a python dictionary thus inherits from the dict built in class.

  `BINARY_MARKER` = '--CIF-BINARY-FORMAT-SECTION--'
  `BLANK` = [' ', '\t', '\r', '\n', '\r\n', '\n\r']
  `EOL` = ['\r', '\n', '\r\n', '\n\r']
  static `LoopHasKey`(loop, key)

    Returns True if the key (string) exist in the array called loop

  `START_COMMENT` = ['"', "'"]
  `exists`(sKey)

    Check if the key exists in the CIF and is non empty. :param sKey: CIF key :type sKey: string :param cif: CIF dictionary :return: True if the key exists in the CIF dictionary and is non empty :rtype: boolean

  `existsInLoop`(sKey)

    Check if the key exists in the CIF dictionary. :param sKey: CIF key :type sKey: string :param cif: CIF dictionary :return: True if the key exists in the CIF dictionary and is non empty :rtype: boolean

  static `isAscii`(_strIn)

    Check if all characters in a string are ascii,

    Parameters: | _strIn (python string) – input string
    Returns: | boolean
    Return type: | boolean

  `loadCHIPLOT`(_strFilename)

    Load the powder diffraction CHIPLOT file and returns the pd_CIF dictionary in the object

    Parameters: | _strFilename (string) – the name of the file to open
    Returns: | the CIF object corresponding to the powder diffraction
    Return type: | dictionary

  `loadCIF`(_strFilename, _bKeepComment=False)

    Load the CIF file and populates the CIF dictionary into the object :param _strFilename: the name of the file to open :type _strFilename: string :param _strFilename: the name of the file to open :type _strFilename: string :return: None

  `pop`(key)
  `popitem`(key)
  `readCIF`(_strFilename, _bKeepComment=False)

    Load the CIF file and populates the CIF dictionary into the object :param _strFilename: the name of the file to open :type _strFilename: string :param _strFilename: the name of the file to open :type _strFilename: string :return: None

  `saveCIF`(_strFilename='test.cif', linesep='n', binary=False)

    Transforms the CIF object in string then write it into the given file :param _strFilename: the of the file to be written :param linesep: line separation used (to force compatibility with windows/unix) :param binary: Shall we write the data as binary (True only for imageCIF/CBF) :type param: string

  `tostring`(_strFilename=None, linesep='n')

    Converts a cif dictionnary to a string according to the CIF syntax

    Parameters: | _strFilename (string) – the name of the filename to be appended in the header of the CIF file
    Returns: | a sting that corresponds to the content of the CIF - file.

class `fabio.cbfimage.``cbfimage`(data=None, header=None, fname=None)

  Bases: `fabio.fabioimage.fabioimage`

  Read the Cif Binary File data format

  static `checkData`(data=None)
  `read`(fname, frame=None)
    Read in header into self.header and
      the data into self.data
  `write`(fname)

    write the file in CBF format :param fname: name of the file :type: string

## `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

  `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: GPLv2+

### Authors:

- Henning O. Sorensen & Erik Knudsen: Center for Fundamental Research: Metal Structures in Four Dimensions; Risoe National Laboratory; Frederiksborgvej 399; DK-4000 Roskilde; email:erik.knudsen@risoe.dk
- Jon Wright & Jérôme Kieffer: European Synchrotron Radiation Facility; Grenoble (France)

class `fabio.edfimage.``Frame`(data=None, header=None, header_keys=None, number=None)

  Bases: `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 countimg number of images at 1

    Returns: | ascii header block
    Return type: | python string with the concatenation of the ascii header and the binary data block

  `parseheader`(block)

    Parse the header in some EDF format from an already open file

    Parameters: | block (string, should be full ascii) – string representing the header block
    Returns: | size of the binary blob

  `setByteCode`(_iVal)
  `setData`(npa=None)

    Setter for data in edf frame

  `swap_needed`()

    Decide if we need to byteswap

class `fabio.edfimage.``edfimage`(data=None, header=None, header_keys=None, frames=None)

  Bases: `fabio.fabioimage.fabioimage`

  Read and try to write the ESRF edf data format

  `appendFrame`(frame=None, data=None, header=None)

    Method used add a frame to an EDF file :param frame: frame to append to edf image :type frame: instance of Frame :return: None

  `bpp`
  `bytecode`
  `capsHeader`

    property: capsHeader of EDF file, i.e. the keys of the header in UPPER case.

  static `checkHeader`(header=None)

    Empty for fabioimage but may be populated by others classes

  `data`

    property: data of EDF file

  `delCapsHeader`()

    deleter for edf capsHeader

  `delData`()

    deleter for edf Data

  `delHeader`()

    Deleter for edf header

  `delHeaderKeys`()

    Deleter for edf header_keys

  `deleteFrame`(frameNb=None)

    Method used to remove a frame from an EDF image. by default the last one is removed. :param frameNb: frame number to remove, by default the last. :type frameNb: integer :return: None

  `dim1`
  `dim2`
  `dims`
  `fastReadData`(filename=None)

    This is a special method that will read and return the data from another file ... The aim is performances, ... but only supports uncompressed files.

    Returns: | data from another file using positions from current edfimage

  `fastReadROI`(filename, coords=None)

    Method reading Region of Interest of another file based on metadata available in current edfimage. The aim is performances, ... but only supports uncompressed files.

    Returns: | ROI-data from another file using positions from current edfimage
    Return type: | numpy 2darray

  `getBpp`()
  `getByteCode`()
  `getCapsHeader`()

    getter for edf headers keys in upper case :return: data for current frame :rtype: dict

  `getData`()

    getter for edf Data :return: data for current frame :rtype: numpy.ndarray

  `getDim1`()
  `getDim2`()
  `getDims`()
  `getHeader`()

    Getter for the headers. used by the property header,

  `getHeaderKeys`()

    Getter for edf header_keys

  `getNbFrames`()

    Getter for number of frames

  `getframe`(num)

    returns the file numbered ‘num’ in the series as a fabioimage

  `header`

    property: header of EDF file

  `header_keys`

    property: header_keys of EDF file

  `next`()

    returns the next file in the series as a fabioimage

  `nframes`

    Getter for number of frames

  `previous`()

    returns the previous file in the series as a fabioimage

  `read`(fname, frame=None)
    Read in header into self.header and
      the data into self.data
  `setBpp`(_iVal)
  `setByteCode`(_iVal)
  `setCapsHeader`(_data)

    Enforces the propagation of the header_keys to the list of frames :param _data: numpy array representing data

  `setData`(_data)

    Enforces the propagation of the data to the list of frames :param _data: numpy array representing data

  `setDim1`(_iVal)
  `setDim2`(_iVal)
  `setHeader`(_dictHeader)

    Enforces the propagation of the header to the list of frames

  `setHeaderKeys`(_listtHeader)

    Enforces the propagation of the header_keys to the list of frames :param _listtHeader: list of the (ordered) keys in the header :type _listtHeader: python list

  `setNbFrames`(val)

    Setter for number of frames ... should do nothing. Here just to avoid bugs

  `swap_needed`()

    Decide if we need to byteswap

  `unpack`()

    Unpack a binary blob according to the specification given in the header and return the dataset

    Returns: | dataset as numpy.ndarray

  `write`(fname, force_type=None, fit2dMode=False)

    Try to write a file check we can write zipped also mimics that fabian was writing uint16 (we sometimes want floats)

    Parameters: | force_type – can be numpy.uint16 or simply “float”
    Returns: | None

## `fabio.fit2dmaskimage` Module

Author: Andy Hammersley, ESRF Translation into python/fabio: Jon Wright, ESRF

class `fabio.fit2dmaskimage.``fit2dmaskimage`(data=None, header=None)

  Bases: `fabio.fabioimage.fabioimage`

  Read and try to write Andy Hammersley’s mask format

  static `checkData`(data=None)
  `read`(fname, frame=None)
    Read in header into self.header and
      the data into self.data
  `write`(fname)

    Try to write a file check we can write zipped also mimics that fabian was writing uint16 (we sometimes want floats)

## `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

  `read`(fname, frame=None)
    Read in header into self.header and
      the data into self.data

## `fabio.GEimage` Module

class `fabio.GEimage.``GEimage`(data=None, header=None)

  Bases: `fabio.fabioimage.fabioimage`

  `getframe`(num)

    Returns a frame as a new fabioimage object

  `next`()

    Get the next image in a series as a fabio image

  `previous`()

    Get the previous image in a series as a fabio image

  `read`(fname, frame=None)

    Read in header into self.header and the data into self.data

  `write`(fname, force_type=<type 'numpy.uint16'>)

    Not yet implemented

`fabio.GEimage.``demo`()

## `fabio.HiPiCimage` Module

Authors: Henning O. Sorensen & Erik Knudsen

  > Center for Fundamental Research: Metal Structures in Four Dimensions Risoe National Laboratory Frederiksborgvej 399 DK-4000 Roskilde email:erik.knudsen@risoe.dk

  - Jon Wright, ESRF

Information about the file format from Masakatzu Kobayashi is highly appreciated

class `fabio.HiPiCimage.``HiPiCimage`(data=None, header=None)

  Bases: `fabio.fabioimage.fabioimage`

  Read HiPic images e.g. collected with a Hamamatsu CCD camera

  `read`(fname, frame=None)
    Read in header into self.header and
      the data into self.data

## `fabio.kcdimage` Module

Authors: Jerome Kieffer, ESRF
  email:jerome.kieffer@esrf.fr

kcd images are 2D images written by the old KappaCCD diffractometer built by Nonius in the 1990’s Based on the edfimage.py parser.

class `fabio.kcdimage.``kcdimage`(data=None, header=None)

  Bases: `fabio.fabioimage.fabioimage`

  Read the Nonius kcd data format

  static `checkData`(data=None)
  `read`(fname, frame=None)
    Read in header into self.header and
      the data into self.data

## `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)

class `fabio.mar345image.``mar345image`(*args, **kwargs)

  Bases: `fabio.fabioimage.fabioimage`

  static `checkData`(data=None)
  `nb_overflow_pixels`()
  `read`(fname, frame=None)

    Read a mar345 image

  `write`(fname)

    Try to write mar345 file. This is still in beta version. It uses CCP4 (LGPL) PCK1 algo from JPA

## `fabio.marccdimage` Module

### Authors:

- Henning O. Sorensen & Erik Knudsen: Center for Fundamental Research: Metal Structures in Four Dimensions; Risoe National Laboratory; Frederiksborgvej 399; DK-4000 Roskilde; email:erik.knudsen@risoe.dk
- Jon Wright: European Synchrotron Radiation Facility; Grenoble (France)

marccdimage can read MarCCD and MarMosaic images including header info.

JPW : Use a parser in case of typos (sorry?)

`fabio.marccdimage.``interpret_header`(header, fmt, names)

  given a format and header interpret it

`fabio.marccdimage.``make_format`(c_def_string)

  Reads the header definition in c and makes the format string to pass to struct.unpack

class `fabio.marccdimage.``marccdimage`(*args, **kwds)

  Bases: `fabio.tifimage.tifimage`

  Read in data in mar ccd format, also MarMosaic images, including header info

## `fabio.OXDimage` Module

Reads Oxford Diffraction Sapphire 3 images

### Authors:

- Henning O. Sorensen & Erik Knudsen: Center for Fundamental Research: Metal Structures in Four Dimensions; Risoe National Laboratory; Frederiksborgvej 399; DK-4000 Roskilde; email:erik.knudsen@risoe.dk
- Jon Wright, Jérôme Kieffer & Gaël Goret: European Synchrotron Radiation Facility; Grenoble (France)

class `fabio.OXDimage.``OXDimage`(data=None, header=None)

  Bases: `fabio.fabioimage.fabioimage`

  Oxford Diffraction Sapphire 3 images reader/writer class

  static `checkData`(data=None)
  `getCompressionRatio`()

    calculate the compression factor obtained vs raw data

  `read`(fname, frame=None)
    Read in header into self.header and
      the data into self.data
  `write`(fname)

    Write Oxford diffraction images: this is still beta :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

### Authors:

- Henning O. Sorensen & Erik Knudsen: Center for Fundamental Research: Metal Structures in Four Dimensions; Risoe National Laboratory; Frederiksborgvej 399; DK-4000 Roskilde; email:erik.knudsen@risoe.dk
- Jon Wright: European Synchrotron Radiation Facility; Grenoble (France)

class `fabio.pilatusimage.``pilatusimage`(*args, **kwds)

  Bases: `fabio.tifimage.tifimage`

  Read in Pilatus format, also pilatus images, including header info

## `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

class `fabio.pnmimage.``pnmimage`(*arg, **kwargs)

  Bases: `fabio.fabioimage.fabioimage`

  static `P1dec`(buf, bytecode)
  static `P2dec`(buf, bytecode)
  static `P3dec`(buf, bytecode)
  static `P4dec`(buf, bytecode)
  static `P5dec`(buf, bytecode)
  static `P6dec`(buf, bytecode)
  static `P7dec`(buf, bytecode)
  static `checkData`(data=None)
  `read`(fname, frame=None)

    try to read PNM images :param fname: name of the file :param frame: not relevant here! PNM is always single framed

  `write`(filename)

## `fabio.tifimage` Module

FabIO class for dealing with TIFF images. In facts wraps TiffIO from V. Armando Solé (available in PyMca) or falls back to PIL

### Authors:

- Henning O. Sorensen & Erik Knudsen: Center for Fundamental Research: Metal Structures in Four Dimensions; Risoe National Laboratory; Frederiksborgvej 399; DK-4000 Roskilde; email:erik.knudsen@risoe.dk
- Jérôme Kieffer: European Synchrotron Radiation Facility; Grenoble (France)

License: GPLv3+

class `fabio.tifimage.``Image_File_Directory`(instring=None, offset=-1)

  Bases: `object`

  `unpack`(instring, offset=-1)

class `fabio.tifimage.``Image_File_Directory_entry`(tag=0, tag_type=0, count=0, offset=0)

  Bases: `object`

  `extract_data`(full_string)
  `unpack`(strInput)

class `fabio.tifimage.``Tiff_header`(string)

  Bases: `object`

class `fabio.tifimage.``tifimage`(*args, **kwds)

  Bases: `fabio.fabioimage.fabioimage`

  Images in TIF format Wraps TiffIO

  `read`(fname, frame=None)

    Wrapper for TiffIO.

  `write`(fname)

    Overrides the fabioimage.write method and provides a simple TIFF image writer. :param fname: name of the file to save the image to @tag_type fname: string or unicode (file?)...

## `fabio.xsdimage` Module

Authors: Jérôme Kieffer, ESRF
  email:jerome.kieffer@esrf.fr

XSDimge are XML files containing numpy arrays

class `fabio.xsdimage.``xsdimage`(data=None, header=None, fname=None)

  Bases: `fabio.fabioimage.fabioimage`

  Read the XSDataImage XML File data format

  `read`(fname, frame=None)

## `fabio.compression` Module

Authors: Jérôme Kieffer, ESRF
  email:jerome.kieffer@esrf.fr

FabIO library containing compression and decompression algorithm for various

`fabio.compression.``compByteOffet_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.``decByteOffet_cython`(stream, size=None)
  Analyze a stream of char with any length of exception:
    2, 4, or 8 bytes integers

  Parameters:

  - stream – string representing the compressed data
  - size – the size of the output array (of longInts)

  Returns: | 1D-ndarray

`fabio.compression.``decByteOffet_numpy`(stream, size=None)
  Analyze a stream of char with any length of exception:
    2, 4, or 8 bytes integers

  Parameters:

  - stream – string representing the compressed data
  - size – the size of the output array (of longInts)

  Returns: | 1D-ndarray

`fabio.compression.``decByteOffet_python`(stream, size)

  Analyze a stream of char with any length of exception (2,4, or 8 bytes integers)

  Parameters:

  - stream – string representing the compressed data
  - size – the size of the output array (of longInts)

  Returns: | 1D-ndarray

`fabio.compression.``decByteOffet_weave`(stream, size)

  Analyze a stream of char with any length of exception (2,4, or 8 bytes integers)

  Parameters:

  - stream – string representing the compressed data
  - size – the size of the output array (of longInts)

  Returns: | 1D-ndarray

`fabio.compression.``decBzip2`(stream)

  Decompress a chunk of data using the bzip2 algorithm from Python

`fabio.compression.``decGzip`(stream)

  Decompress a chunk of data using the gzip algorithm from Python or alternatives if possible

`fabio.compression.``decKM4CCD`(raw_8, raw_16=None, raw_32=None)

  Modified byte offset decompressor used in Oxford Diffraction images

  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)

  Modified CCP4 pck decompressor used in MAR345 images

  Parameters: | stream – string or file
  Returns: | numpy.ndarray (square array)

`fabio.compression.``decTY1`(raw_8, raw_16=None, raw_32=None)

  Modified byte offset decompressor used in Oxford Diffraction images

  Parameters:

  - raw_8 – strings containing raw data with integer 8 bits
  - raw_16 – strings containing raw data with integer 16 bits
  - raw_32 – strings containing raw data with integer 32 bits

  Returns: | numpy.ndarray

`fabio.compression.``decZlib`(stream)

  Decompress a chunk of data using the zlib algorithm from Python

`fabio.compression.``endianness`()

  Return the native endianness of the system

`fabio.compression.``md5sum`(blob)

  returns the md5sum of an object...

## `fabio.converters` Module

Converter module. This is for the moment empty (populated only with almost pass through anonymous functions) but aims to be populated with more sofisticated translators ...

`fabio.converters.``convert_data`(inp, outp, data)

  Return data converted to the output format ... over-simplistic implementation for the moment ... :param inp,outp: input/output format like “cbfimage” :param data(ndarray): the actual dataset to be transformed

`fabio.converters.``convert_data_integer`(data)

  convert data to integer

`fabio.converters.``convert_header`(inp, outp, header)

  return header converted to the output format :param inp,outp: input/output format like “cbfimage” :param header(dict):the actual set of headers to be transformed

## `fabio.datIO` Module

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

class `fabio.TiffIO.``TiffIO`(filename, mode=None, cache_length=20, mono_output=False)

  Bases: `object`

  `getData`(nImage, **kw)
  `getImage`(nImage)
  `getImageFileDirectories`(fd=None)
  `getInfo`(nImage, **kw)
  `getNumberOfImages`()
  `writeImage`(image0, info=None, software=None, date=None)

## `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

### Navigation

- index
- modules |
- previous |
- FabIO 0.1.3 documentation »