How to use the fabio.edfimage.EdfImage 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 / 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 / silx / examples / imageStack.py View on Github external
def create_edf_url(file_name):
    """ create a simple DataUrl with a .edf file"""
    dsc = fabio.edfimage.EdfImage(data=create_random_image(), header={})
    dsc.write(file_name)
    return [DataUrl(file_path=file_name,
                    data_slice=(0,),
                    scheme='fabio'), ]
github ronpandolfi / Xi-cam / pipeline / formats.py View on Github external
#not really useful at this point
        if not self.header:
            self.header = {}
            self.header['shape'] = self.rawdata.shape

    def getframe(self, frame=0):
        return self.rawdata[frame]

    def __getitem__(self, item):
        return self.rawdata[item]

    def close(self):
        pass


class EdfImage(edfimage.EdfImage):
    DEFAULT_EXTENTIONS = DEFAULT_EXTENSIONS = ['edf']

    def read(self, f, frame=None):
        return super(EdfImage, self).read(f, frame)

    def _readheader(self, f):
        super(EdfImage, self)._readheader(f)
        f = f.name.replace('.edf', '.txt')
        if os.path.isfile(f):
            self.header.update(self.scanparas(f))

    @staticmethod
    def scanparas(path):
        if not os.path.isfile(path):
            return dict()
github silx-kit / fabio / fabio / file_series.py View on Github external
def frames(self):
        """Returns an iterator throug all frames of all filenames of this
        file series."""
        import fabio.edfimage
        nframe = 0
        for filename in self.__iter_filenames():

            if self.use_edf_shortcut:
                info = FilenameObject(filename=filename)
                # It is the supported formats
                if fabio.edfimage.EdfImage in info.codec_classes:
                    # Custom iterator implementation
                    frames = fabio.edfimage.EdfImage.lazy_iterator(filename)
                    for frame in frames:
                        frame._set_container(self, nframe)
                        yield frame
                        nframe += 1
                    continue

            # Default implementation
            with fabio.open(filename) as image:
                if image.nframes == 0:
                    # The container is empty
                    pass
                elif image.nframes == 1:
                    yield image
                else:
github silx-kit / fabio / fabio / edfimage.py View on Github external
else:
                # There can be only a single general block
                edf.generalframe = frame
                if frame.blobsize > 0:
                    # Skip the blob
                    blobend = frame.start+frame.blobsize
                    frame.file.seek(blobend)

        infile.close()


Frame = EdfFrame
"""Compatibility code with fabio <= 0.8"""

edfimage = EdfImage
github silx-kit / pyFAI / pyFAI / utils / header_utils.py View on Github external
def get_monitor_value(image, monitor_key):
    """Return the monitor value from an image using an header key.

    :param fabio.fabioimage.FabioImage image: Image containing the header
    :param str monitor_key: Key containing the monitor
    :return: returns the monitor else raise an exception
    :rtype: float
    :raise MonitorNotFound: when the expected monitor is not found on the
        header
    """
    if monitor_key is None:
        return Exception("No monitor defined")

    if isinstance(image, fabio.edfimage.EdfImage):
        return _get_monitor_value_from_edf(image, monitor_key)
    elif isinstance(image, fabio.numpyimage.NumpyImage):
        return _get_monitor_value_from_edf(image, monitor_key)
    elif isinstance(image, fabio.hdf5image.Hdf5Image):
        return _get_monitor_value_from_hdf5(image, monitor_key)
    else:
        raise Exception("File format '%s' unsupported" % type(image))
github silx-kit / fabio / fabio / edfimage.py View on Github external
def __init__(self, data=None, header=None, number=None):
        header = EdfImage.check_header(header)
        super(EdfFrame, self).__init__(data, header=header)

        self._data_compression = None
        self._data_swap_needed = None
        self._data = data
        self.start = None
        """Start position of the raw data blob in the file"""
        self.blobsize = None
        """Size of the raw data blob in the file (including padding)"""
        self.size = None
        """Size of the retrieved data (after unpacking and decompressing)"""
        self.file = None
        """Opened file object with locking capabilities"""
        self._dtype = None
        self.incomplete_data = False
        self.bfname = None