Example #1
0
    def _read_cbf_image(self):
        start_tag = binascii.unhexlify("0c1a04d5")

        with self.open_file(self._image_file, "rb") as fh:
            data = fh.read()
        data_offset = data.find(start_tag) + 4
        cbf_header = self._parse_cbf_header(data[:data_offset - 4].decode(
            "ascii", "ignore"))

        if cbf_header["byte_offset"]:
            pixel_values = uncompress(
                packed=data[data_offset:data_offset + cbf_header["size"]],
                fast=cbf_header["fast"],
                slow=cbf_header["slow"],
            )
        elif cbf_header["no_compression"]:
            assert len(self.get_detector()) == 1
            with self.open_file(self._image_file) as f:
                f.read(data_offset)
                pixel_values = read_int32(streambuf(f), cbf_header["length"])
            pixel_values.reshape(
                flex.grid(cbf_header["slow"], cbf_header["fast"]))

        else:
            raise ValueError(
                "Compression of type other than byte_offset or none is not supported (contact authors)"
            )

        return pixel_values
Example #2
0
def test_compress_decompress():
    x, y = 10, 10

    data = flex.int(x * y, 1)
    data[10] = 44369
    data[11] = 214
    compressed = compress(data)
    uncompressed = uncompress(compressed, x, y)

    assert list(data) == list(uncompressed)
Example #3
0
    def _read_cbf_image(self):
        start_tag = binascii.unhexlify("0c1a04d5")

        with self.open_file(self._image_file, "rb") as fh:
            data = fh.read()
        data_offset = data.find(start_tag) + 4
        cbf_header = self._parse_cbf_header(data[:data_offset - 4].decode(
            "ascii", "ignore"))

        pixel_values = uncompress(
            packed=data[data_offset:data_offset + cbf_header["size"]],
            fast=cbf_header["fast"],
            slow=cbf_header["slow"],
        )

        return pixel_values