def _read_raw_data(self, f): """Read raw data from a positioned file""" # is this image a type we can read? assert self._data_type in ["h", "f", "B", "l", "b", "H", "I", "d"] if self._data_type == "f": raw_data = read_float32(streambuf(f), self._image_num_elements) elif self._data_type == "B": raw_data = read_uint8(streambuf(f), self._image_num_elements) elif self._data_type == "h": raw_data = read_int16(streambuf(f), self._image_num_elements) elif self._data_type == "H": raw_data = read_uint16(streambuf(f), self._image_num_elements) elif self._data_type == "l": raw_data = read_int32(streambuf(f), self._image_num_elements) elif self._data_type == "I": 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): """Get the pixel intensities (i.e. read the image and return as a flex array of integers.)""" # currently have no non-little-endian machines... assert len(self.get_detector()) == 1 image_size = self.get_detector()[0].get_image_size() with self.open_file(self._image_file) as fh: fh.seek(self._header_size) raw_data = read_uint16(streambuf(fh), int(image_size[0] * image_size[1])) raw_data.reshape(flex.grid(image_size[1], image_size[0])) return raw_data
def _get_endianic_raw_data(self, size): big_endian = self._header_dictionary["BYTE_ORDER"] == "big_endian" with self.open_file(self._image_file, "rb") as fh: fh.seek(self._header_size) if big_endian == is_big_endian(): raw_data = read_uint16(streambuf(fh), int(size[0] * size[1])) else: raw_data = read_uint16_bs(streambuf(fh), int(size[0] * size[1])) # note that x and y are reversed here raw_data.reshape(flex.grid(size[1], size[0])) return raw_data
def get_raw_data(self): """Get the pixel intensities (i.e. read the image and return as a flex array of integers.)""" # currently have no non-little-endian machines... assert self._tiff_byte_order == FormatTIFF.LITTLE_ENDIAN bias = int(round(self._get_rayonix_bias())) assert len(self.get_detector()) == 1 size = self.get_detector()[0].get_image_size() f = FormatTIFF.open_file(self._image_file) f.read(self._header_size) raw_data = read_uint16(streambuf(f), int(size[0] * size[1])) - bias image_size = self.get_detector()[0].get_image_size() raw_data.reshape(flex.grid(image_size[1], image_size[0])) return raw_data
def get_raw_data(self, index): # 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": raw_data = read_float32(streambuf(f), self._image_num_elements) elif self._data_type == "B": raw_data = read_uint8(streambuf(f), self._image_num_elements) elif self._data_type == "h": raw_data = read_int16(streambuf(f), self._image_num_elements) elif self._data_type == "H": raw_data = read_uint16(streambuf(f), self._image_num_elements) elif self._data_type == "l": raw_data = read_int32(streambuf(f), self._image_num_elements) elif self._data_type == "I": 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