How to use the fabio.fabioimage function in fabio

To help you get started, we’ve selected a few fabio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github silx-kit / fabio / fabio / fabioformats.py View on Github external
def register(codec_class):
    """Register a class format to the core fabio library"""
    global _extension_cache
    if not issubclass(codec_class, fabioimage.FabioImage):
        raise AssertionError("Expected subclass of FabioImage class but found %s" % type(codec_class))
    _registry[codec_class.codec_name()] = codec_class
    # clean u[p the cache
    _extension_cache = None
github silx-kit / fabio / fabio / tifimage.py View on Github external
def __init__(self, *args, **kwds):
        """ Tifimage constructor adds an nbits member attribute """
        self.nbits = None
        fabioimage.FabioImage.__init__(self, *args, **kwds)
        self._tiffio = None
        self.lib = None
github silx-kit / fabio / fabio / hdf5image.py View on Github external
def __init__(self, *arg, **kwargs):
        """
        Generic constructor
        """
        if not h5py:
            raise RuntimeError("fabio.Hdf5Image cannot be used without h5py. Please install h5py and restart")

        fabioimage.FabioImage.__init__(self, *arg, **kwargs)
        self.hdf5 = None
        self.dataset = None
github silx-kit / fabio / fabio / pixiimage.py View on Github external
__contact__ = "wright@esrf.fr"
__license__ = "MIT"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
__date__ = "03/04/2020"

import numpy
import os
import logging

logger = logging.getLogger(__name__)

from . import fabioimage
from .fabioutils import previous_filename, next_filename


class PixiImage(fabioimage.FabioImage):

    DESCRIPTION = "Pixi file format"

    DEFAULT_EXTENSIONS = []

    _need_a_seek_to_read = True

    _IMAGE_WIDTH = 476
    _IMAGE_HEIGHT = 512
    _MAGIC_SIZE = 4
    _HEADER_SIZE = 24
    _PIXEL_DEPTH = 2
    """Each pixel is stored as UINT16"""
    _PIXEL_COUNT = _IMAGE_WIDTH * _IMAGE_HEIGHT
    _IMAGE_SIZE = _PIXEL_COUNT * _PIXEL_DEPTH
    _FRAME_SIZE = _HEADER_SIZE + _IMAGE_SIZE
github silx-kit / fabio / fabio / hdf5image.py View on Github external
import logging
import os
import posixpath
from . import fabioimage

logger = logging.getLogger(__name__)

try:
    import h5py
except ImportError:
    h5py = None
from .fabioutils import previous_filename, next_filename


class Hdf5Frame(fabioimage.FabioFrame):
    """Identify a slice of dataset from an HDF5 file"""

    def __init__(self, hdf5image, frame_num):
        if not isinstance(hdf5image, Hdf5Image):
            raise TypeError("Expected class %s", Hdf5Image)
        data = hdf5image.dataset[frame_num, :, :]
        super(Hdf5Frame, self).__init__(data=data, header=hdf5image.header)
        self.hdf5 = hdf5image.hdf5
        self.dataset = hdf5image.dataset
        self.filename = hdf5image.filename
        self._nframes = hdf5image.nframes
        self.header = hdf5image.header
        self.currentframe = frame_num


class Hdf5Image(fabioimage.FabioImage):
github silx-kit / fabio / fabio / pixiimage.py View on Github external
def _get_frame(self, num):
        """Inherited function returning a FabioFrame"""
        if num < 0:
            raise IndexError("Requested frame id:%d out of bound" % num)
        if num >= self.nframes:
            raise IndexError("Requested frame id:%d out of bound" % num)

        newheader = {}
        for k in self.header.keys():
            newheader[k] = self.header[k]
        with self._open(self.filename, "rb") as infile:
            data = self._readdata(infile, num)
        frame = fabioimage.FabioFrame(data=data, header=newheader)
        frame._set_container(self, num)
        frame._set_file_container(self, num)
        return frame
github silx-kit / silx / examples / hdf5widget.py View on Github external
def get_edf_with_100000_frames():
    ID = "frame100000"
    if ID in _file_cache:
        return _file_cache[ID].name

    tmp = tempfile.NamedTemporaryFile(prefix=ID + "_", suffix=".edf", delete=True)

    fabiofile = None
    for framre_id in range(100000):
        data = numpy.array([[framre_id, 50], [50, 10]])
        if fabiofile is None:
            header = fabio.fabioimage.OrderedDict()
            header["nb_frames"] = "100000"
            fabiofile = fabio.edfimage.EdfImage(data, header)
        else:
            header = fabio.fabioimage.OrderedDict()
            header["frame_nb"] = framre_id
            fabiofile.append_frame(fabio.edfimage.Frame(data, header, framre_id))
    fabiofile.write(tmp.name)

    _file_cache[ID] = tmp
    return tmp.name
github silx-kit / fabio / fabio / numpyimage.py View on Github external
def getframe(self, num):
        """ returns the frame numbered 'num' in the stack if applicable"""
        if self.nframes > 1:
            frame = None
            if (num >= 0) and num < self.nframes:
                data = self.dataset[num]
                frame = self.__class__(data=data, header=self.header)
                frame.dataset = self.dataset
                frame._nframes = self.nframes
                frame.currentframe = num
            else:
                raise IndexError("getframe %s out of range [%s %s[" % (num, 0, self.nframes))
        else:
            frame = fabioimage.FabioImage.getframe(self, num)
        return frame
github silx-kit / fabio / fabio / __init__.py View on Github external
__date__ = "20/06/2016"
__status__ = "stable"


import os
import logging
logging.basicConfig()
project = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
# try:
#     from ._version import __date__ as date  # noqa
#     from ._version import version, version_info, hexversion, strictversion  # noqa
# except ImportError:
#     raise RuntimeError("Do NOT use %s from its sources: build it and use the built version" % project)

from . import fabioimage
factory = fabioimage.FabioImage.factory
from . import openimage
from .fabioutils import COMPRESSORS, jump_filename, FilenameObject, \
        previous_filename, next_filename, deconstruct_filename, \
        extract_filenumber, getnum, construct_filename, exists

# Compatibility with outside world:
filename_object = FilenameObject

from .openimage import openimage as open
from .openimage import openheader as openheader


def tests():
    """
    Run the FabIO test suite.
github silx-kit / pyFAI / pyFAI / massif.py View on Github external
def __init__(self, data=None):
        """

        """
        if isinstance(data, six.string_types) and os.path.isfile(data):
            self.data = fabio.open(data).data.astype("float32")
        elif isinstance(data, fabio.fabioimage.fabioimage):
            self.data = data.data.astype("float32")
        else:
            try:
                self.data = data.astype("float32")
            except Exception as error:
                logger.error("Unable to understand this type of data %s: %s", data, error)
        self._bilin = Bilinear(self.data)
        self._blured_data = None
        self._median_data = None
        self._labeled_massif = None
        self._number_massif = None
        self._valley_size = None
        self._binned_data = None
        self.binning = None  # Binning is 2-list usually
        self._sem = threading.Semaphore()
        self._sem_label = threading.Semaphore()