How to use the fabio.edfimage.EdfFrame 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 / 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
        """If set, the data must be read from this file and not from the blob
github silx-kit / fabio / fabio / edfimage.py View on Github external
# iterate over all frames
                yield frame
                index += 1

            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 / fabio / fabio / edfimage.py View on Github external
def append_frame(self, 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
        """
        if isinstance(frame, EdfFrame):
            self._frames.append(frame)
        elif hasattr(frame, "header") and hasattr(frame, "data"):
            self._frames.append(EdfFrame(frame.data, frame.header))
        else:
            self._frames.append(EdfFrame(data, header))
github silx-kit / fabio / fabio / edfimage.py View on Github external
raise IOError("Invalid first header")
                self._incomplete_file = True
                break

            if value.header is None:
                # end of file
                if len(self._frames) == 0:
                    raise IOError("Empty file")
                break

            if value.data_format_version is None:
                is_general_header = False
            else:
                is_general_header = True

            frame = EdfFrame()
            # The file descriptor is used in _extract_header_metadata and must be defined before using it
            frame.file = infile

            # PB38k20190607: any need for frame._set_container(self,len(self._frames))?
            frame._index=len(self._frames)

            defaultheader=None
            if not is_general_header:
                # This is not a general block, include a general header
                if self.generalframe is not None:
                    defaultheader=self.generalframe._header

            capsHeader = frame._create_header(value.header,defaultheader)

            # get frame.blobsize
            if value.binary_size is None:
github silx-kit / fabio / fabio / edfimage.py View on Github external
raise Exception("Data with empty shape is unsupported")
            elif dim == 1:
                logger.warning("Data in 1d dimension will be stored as a 2d dimension array")
                # make sure we do not change the shape of the input data
                stored_data = numpy.array(data, copy=False)
                stored_data.shape = (1, len(data))
            elif dim == 2:
                stored_data = data
            elif dim >= 3:
                raise Exception("Data dimension too big. Only 1d or 2d arrays are supported.")

        fabioimage.FabioImage.__init__(self, stored_data, header)

        # frames
        if frames is None:
            frame = EdfFrame(data=self.data, header=self.header)
            self._frames = [frame]
        else:
            self._frames = frames

        # generalframe
        self.generalframe = generalframe
github silx-kit / fabio / fabio / edfimage.py View on Github external
raise IOError("Invalid first header")
                break

            if value.header is None:
                # end of file
                if index == 0:
                    infile.close()
                    raise IOError("Empty file")
                break

            if value.data_format_version is None:
                is_general_header = False
            else:
                is_general_header = True

            frame = EdfFrame()
            frame.file = infile
            frame._set_container(edf, index)
            frame._set_file_container(edf, index)

            defaultheader=None
            if not is_general_header:
                # This is a standard block, use the general header as default
                if edf.generalframe is not None:
                    defaultheader=edf.generalframe._header

            capsHeader = frame._create_header(value.header,defaultheader)

            if value.binary_size is None:
                # Try again computing blobsize
                if "SIZE" in capsHeader:
                    try:
github silx-kit / fabio / fabio / edfimage.py View on Github external
def _get_any_frame(self):
        """Returns the current if available, else create and return a new empty
        frame."""
        try:
            return self._frames[self.currentframe]
        except AttributeError:
            frame = EdfFrame()
            self._frames = [frame]
            return frame
        except IndexError:
            if self.currentframe < len(self._frames):
                frame = EdfFrame()
                self._frames.append(frame)
                return frame
            raise
github silx-kit / fabio / fabio / edfimage.py View on Github external
def _get_any_frame(self):
        """Returns the current if available, else create and return a new empty
        frame."""
        try:
            return self._frames[self.currentframe]
        except AttributeError:
            frame = EdfFrame()
            self._frames = [frame]
            return frame
        except IndexError:
            if self.currentframe < len(self._frames):
                frame = EdfFrame()
                self._frames.append(frame)
                return frame
            raise
github silx-kit / fabio / fabio / edfimage.py View on Github external
def append_frame(self, 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
        """
        if isinstance(frame, EdfFrame):
            self._frames.append(frame)
        elif hasattr(frame, "header") and hasattr(frame, "data"):
            self._frames.append(EdfFrame(frame.data, frame.header))
        else:
            self._frames.append(EdfFrame(data, header))