Beispiel #1
0
    def get_raw_data(self, index):

        from boost.python import streambuf
        from scitbx.array_family import flex

        # is this image a type we can read?
        assert self._data_type in ["h", "f", "B", "l", "b", "H", "I", "d"]

        with FormatGatanDM4.open_file(self._image_file, "rb") as f:
            f.seek(self._data_offset)

            skip_bytes = index * self._image_num_elements * self._data_size
            f.seek(skip_bytes, whence=1)

            if self._data_type == "f":
                from dxtbx import read_float32

                raw_data = read_float32(streambuf(f), self._image_num_elements)
            elif self._data_type == "B":
                from dxtbx import read_uint8

                raw_data = read_uint8(streambuf(f), self._image_num_elements)
            elif self._data_type == "h":
                from dxtbx import read_int16

                raw_data = read_int16(streambuf(f), self._image_num_elements)
            elif self._data_type == "H":
                from dxtbx import read_uint16

                raw_data = read_uint16(streambuf(f), self._image_num_elements)
            elif self._data_type == "l":
                from dxtbx import read_int32

                raw_data = read_int32(streambuf(f), self._image_num_elements)
            elif self._data_type == "I":
                from dxtbx import read_uint32

                raw_data = read_uint32(streambuf(f), self._image_num_elements)

            # no C++ reader for remaining types (should be unusual anyway)
            else:
                vals = struct.unpack(
                    self._byteord + self._data_type * self._image_num_elements,
                    f.read(self._data_size * self._image_num_elements),
                )
                if self._data_type == "d":
                    raw_data = flex.double(vals)
                if self._data_type in ["b", "?"]:
                    raw_data = flex.int(vals)

        raw_data.reshape(flex.grid(self._image_size[1], self._image_size[0]))
        return raw_data
    def get_raw_data(self, index):

        from boost.python import streambuf
        from scitbx.array_family import flex

        # is this image a type we can read?
        assert self._data_type in ['h', 'f', 'B', 'l', 'b', 'H', 'I', 'd']

        with FormatGatanDM4.open_file(self._image_file, 'rb') as f:
            f.seek(self._data_offset)

            skip_bytes = index * self._image_num_elements * self._data_size
            f.seek(skip_bytes, whence=1)

            if self._data_type == 'f':
                from dxtbx import read_float32
                raw_data = read_float32(streambuf(f), self._image_num_elements)
            elif self._data_type == 'B':
                from dxtbx import read_uint8
                raw_data = read_uint8(streambuf(f), self._image_num_elements)
            elif self._data_type == 'h':
                from dxtbx import read_int16
                raw_data = read_int16(streambuf(f), self._image_num_elements)
            elif self._data_type == 'H':
                from dxtbx import read_uint16
                raw_data = read_uint16(streambuf(f), self._image_num_elements)
            elif self._data_type == 'l':
                from dxtbx import read_int32
                raw_data = read_int32(streambuf(f), self._image_num_elements)
            elif self._data_type == 'I':
                from dxtbx import read_uint32
                raw_data = read_uint32(streambuf(f), self._image_num_elements)

            # no C++ reader for remaining types (should be unusual anyway)
            else:
                vals = struct.unpack(
                    self._byteord + self._data_type * self._image_num_elements,
                    f.read(self._data_size * self._image_num_elements))
                if self._data_type == 'd':
                    raw_data = flex.double(vals)
                if self._data_type in ['b', '?']:
                    raw_data = flex.int(vals)

        raw_data.reshape(flex.grid(self._image_size[1], self._image_size[0]))
        return raw_data