def get_raw_data(self): '''Get the pixel intensities (i.e. read the image and return as a flex array of integers.)''' from boost.python import streambuf from dxtbx import read_uint16, read_uint16_bs, is_big_endian from scitbx.array_family import flex assert(len(self.get_detector()) == 1) panel = self.get_detector()[0] size = panel.get_image_size() f = FormatSMVADSC.open_file(self._image_file, 'rb') f.read(self._header_size) if self._header_dictionary['BYTE_ORDER'] == 'big_endian': big_endian = True else: big_endian = False if big_endian == is_big_endian(): raw_data = read_uint16(streambuf(f), int(size[0] * size[1])) else: raw_data = read_uint16_bs(streambuf(f), int(size[0] * size[1])) image_size = panel.get_image_size() raw_data.reshape(flex.grid(image_size[1], image_size[0])) return raw_data
def read_smv_image(image_file): from boost.python import streambuf from dxtbx import read_uint16, read_uint16_bs, is_big_endian from scitbx.array_family import flex header_size, header_dictionary = get_smv_header(image_file) f = open(image_file, 'rb') f.read(header_size) if header_dictionary['BYTE_ORDER'] == 'big_endian': big_endian = True else: big_endian = False image_size = (int(header_dictionary['SIZE1']), int(header_dictionary['SIZE2'])) if big_endian == is_big_endian(): raw_data = read_uint16(streambuf(f), int(image_size[0] * image_size[1])) else: raw_data = read_uint16_bs(streambuf(f), int(image_size[0] * image_size[1])) raw_data.reshape(flex.grid(image_size[1], 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.)''' from boost.python import streambuf from dxtbx import read_uint16, read_uint16_bs, is_big_endian from scitbx.array_family import flex assert (len(self.get_detector()) == 1) panel = self.get_detector()[0] size = panel.get_image_size() f = FormatSMVNOIR.open_file(self._image_file, 'rb') f.read(self._header_size) if self._header_dictionary['BYTE_ORDER'] == 'big_endian': big_endian = True else: big_endian = False if big_endian == is_big_endian(): raw_data = read_uint16(streambuf(f), int(size[0] * size[1])) else: raw_data = read_uint16_bs(streambuf(f), int(size[0] * size[1])) image_size = panel.get_image_size() raw_data.reshape(flex.grid(image_size[1], 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.)''' from boost.python import streambuf from dxtbx import read_uint16, read_uint16_bs, is_big_endian from scitbx.array_family import flex f = self.open_file(self._image_file, 'rb') f.read(self._header_size) if self._header_dictionary['BYTE_ORDER'] == 'big_endian': big_endian = True else: big_endian = False if big_endian == is_big_endian(): raw_data = read_uint16(streambuf(f), int(512 * 512)) else: raw_data = read_uint16_bs(streambuf(f), int(512 * 512)) image_size = (512, 512) raw_data.reshape(flex.grid(image_size[1], image_size[0])) # split into separate panels self._raw_data = [] d = self.get_detector() for panel in d: xmin, ymin, xmax, ymax = self.coords[panel.get_name()] self._raw_data.append(raw_data[ymin:ymax, xmin:xmax]) return tuple(self._raw_data)
def get_raw_data(self): '''Get the pixel intensities (i.e. read the image and return as a flex array of integers.)''' from boost.python import streambuf from dxtbx import read_uint16, read_uint16_bs, is_big_endian from scitbx.array_family import flex f = self.open_file(self._image_file, 'rb') f.read(self._header_size) nx = int(self._header_dictionary['SIZE1']) # number of pixels ny = int(self._header_dictionary['SIZE2']) # number of pixels if self._header_dictionary['BYTE_ORDER'] == 'big_endian': big_endian = True else: big_endian = False if big_endian == is_big_endian(): raw_data = read_uint16(streambuf(f), int(nx * ny)) else: raw_data = read_uint16_bs(streambuf(f), int(nx * ny)) # note that x and y are reversed here raw_data.reshape(flex.grid(ny, nx)) self._raw_data = raw_data return self._raw_data
def get_raw_data(self): '''Get the pixel intensities (i.e. read the image and return as a flex array of integers.)''' from boost.python import streambuf from dxtbx import read_uint16, read_uint16_bs, is_big_endian from scitbx.array_family import flex f = self.open_file(self._image_file, 'rb') header_size = int(self.header_dict['HDRBLKS']) * 512 f.read(header_size) # 16 bits per pixel assert int(self.header_dict['NPIXELB'].split()[0]) == 2 nrows = int(self.header_dict['NROWS'].split()[0]) ncols = int(self.header_dict['NCOLS'].split()[0]) if is_big_endian(): raw_data = read_uint16_bs(streambuf(f), nrows * ncols) else: raw_data = read_uint16(streambuf(f), nrows * ncols) image_size = (nrows, ncols) raw_data.reshape(flex.grid(image_size[0], image_size[1])) 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.)""" from boost.python import streambuf from dxtbx import read_uint16, read_uint16_bs, is_big_endian from scitbx.array_family import flex assert len(self.get_detector()) == 1 image_pedestal = 40 panel = self.get_detector()[0] size = panel.get_image_size() f = FormatSMVADSCSN.open_file(self._image_file, "rb") f.read(self._header_size) if self._header_dictionary["BYTE_ORDER"] == "big_endian": big_endian = True else: big_endian = False if big_endian == is_big_endian(): raw_data = read_uint16(streambuf(f), int(size[0] * size[1])) else: raw_data = read_uint16_bs(streambuf(f), int(size[0] * size[1])) # apply image pedestal, will result in *negative pixel values* raw_data -= image_pedestal image_size = panel.get_image_size() raw_data.reshape(flex.grid(image_size[1], 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.)""" from boost.python import streambuf from dxtbx import read_uint16, read_uint16_bs, is_big_endian from scitbx.array_family import flex assert len(self.get_detector()) == 1 image_pedestal = int(self._header_dictionary["IMAGE_PEDESTAL"]) panel = self.get_detector()[0] size = panel.get_image_size() f = FormatSMVADSCSN.open_file(self._image_file, "rb") f.read(self._header_size) if self._header_dictionary["BYTE_ORDER"] == "big_endian": big_endian = True else: big_endian = False if big_endian == is_big_endian(): raw_data = read_uint16(streambuf(f), int(size[0] * size[1])) else: raw_data = read_uint16_bs(streambuf(f), int(size[0] * size[1])) # apply image pedestal, will result in *negative pixel values* raw_data -= image_pedestal image_size = panel.get_image_size() raw_data.reshape(flex.grid(image_size[1], image_size[0])) return raw_data
def read_smv_image(image_file): from boost.python import streambuf from dxtbx import read_uint16, read_uint16_bs, is_big_endian from scitbx.array_family import flex header_size, header_dictionary = get_smv_header(image_file) with open(image_file, "rb") as f: f.seek(header_size) if header_dictionary["BYTE_ORDER"] == "big_endian": big_endian = True else: big_endian = False image_size = (int(header_dictionary["SIZE1"]), int(header_dictionary["SIZE2"])) if big_endian == is_big_endian(): raw_data = read_uint16(streambuf(f), int(image_size[0] * image_size[1])) else: raw_data = read_uint16_bs(streambuf(f), int(image_size[0] * image_size[1])) raw_data.reshape(flex.grid(image_size[1], 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.)""" from boost.python import streambuf from dxtbx import read_uint16, read_uint16_bs, is_big_endian from scitbx.array_family import flex assert len(self.get_detector()) == 1 image_pedestal = 1 try: image_pedestal = float(self._header_dictionary["ADC_OFFSET"]) except KeyError: pass panel = self.get_detector()[0] size = panel.get_image_size() f = FormatSMVJHSim.open_file(self._image_file, "rb") f.read(self._header_size) if self._header_dictionary["BYTE_ORDER"] == "big_endian": big_endian = True else: big_endian = False if big_endian == is_big_endian(): raw_data = read_uint16(streambuf(f), int(size[0] * size[1])) else: raw_data = read_uint16_bs(streambuf(f), int(size[0] * size[1])) # apply image pedestal, will result in *negative pixel values* # this is a horrible idea since raw_data is unsigned # see all instances of image_pedestal in dxtbx raw_data -= int(image_pedestal) image_size = panel.get_image_size() raw_data.reshape(flex.grid(image_size[1], 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.)""" # It is better to catch FORMAT 86 here and fail with a sensible error msg # as soon as something is attempted with the image data rather than in # the understand method. Otherwise the user gets FormatBruker reading the # image improperly but without failing if self.header_dict["FORMAT"] != "100": raise Sorry( "Only FORMAT 100 images from the Photon II are currently " "supported") f = self.open_file(self._image_file, "rb") header_size = int(self.header_dict["HDRBLKS"]) * 512 f.read(header_size) if is_big_endian(): read_2b = read_uint16_bs read_4b = read_uint32_bs else: read_2b = read_uint16 read_4b = read_uint32 # NPIXELB stores the number of bytes/pixel for the data and the underflow # table. We expect 1 byte for underflows and either 2 or 1 byte per pixel # for the data npixelb = [int(e) for e in self.header_dict["NPIXELB"].split()] assert npixelb[1] == 1 if npixelb[0] == 1: read_data = read_uint8 elif npixelb[0] == 2: read_data = read_2b else: raise IncorrectFormatError( "{0} bytes per pixel is not supported".format(npixelb[0])) nrows = int(self.header_dict["NROWS"].split()[0]) ncols = int(self.header_dict["NCOLS"].split()[0]) raw_data = read_data(streambuf(f), nrows * ncols) image_size = (nrows, ncols) raw_data.reshape(flex.grid(*image_size)) (num_underflows, num_2b_overflows, num_4b_overflows) = [ int(e) for e in self.header_dict["NOVERFL"].split() ] # read underflows if num_underflows > 0: # stored values are padded to a multiple of 16 bytes nbytes = num_underflows + 15 & ~(15) underflow_vals = read_uint8(streambuf(f), nbytes)[:num_underflows] else: underflow_vals = None # handle 2 byte overflows if num_2b_overflows > 0: # stored values are padded to a multiple of 16 bytes nbytes = num_2b_overflows * 2 + 15 & ~(15) overflow_vals = read_2b(streambuf(f), nbytes // 2)[:num_2b_overflows] overflow = flex.int(nrows * ncols, 0) sel = (raw_data == 255).as_1d() overflow.set_selected(sel, overflow_vals - 255) overflow.reshape(flex.grid(*image_size)) raw_data += overflow # handle 4 byte overflows if num_4b_overflows > 0: # stored values are padded to a multiple of 16 bytes nbytes = num_4b_overflows * 4 + 15 & ~(15) overflow_vals = read_4b(streambuf(f), nbytes // 4)[:num_4b_overflows] overflow = flex.int(nrows * ncols, 0) sel = (raw_data == 65535).as_1d() overflow.set_selected(sel, overflow_vals - 65535) overflow.reshape(flex.grid(*image_size)) raw_data += overflow # handle underflows if underflow_vals is not None: sel = (raw_data == 0).as_1d() underflow = flex.int(nrows * ncols, 0) underflow.set_selected(sel, underflow_vals) underflow.reshape(flex.grid(*image_size)) raw_data += underflow # handle baseline. num_underflows == -1 means no baseline subtraction. See # https://github.com/cctbx/cctbx_project/files/1262952/BISFrameFileFormats.zip if num_underflows != -1: num_exposures = [int(e) for e in self.header_dict["NEXP"].split()] baseline = num_exposures[2] raw_data += baseline 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.)''' from boost.python import streambuf from dxtbx import read_uint8, read_uint16, read_uint16_bs, read_uint32, read_uint32_bs from dxtbx import is_big_endian from scitbx.array_family import flex f = self.open_file(self._image_file, 'rb') header_size = int(self.header_dict['HDRBLKS']) * 512 f.read(header_size) if is_big_endian(): read_2b = read_uint16_bs read_4b = read_uint32_bs else: read_2b = read_uint16 read_4b = read_uint32 # NPIXELB stores the number of bytes/pixel for the data and the underflow # table. We expect 1 byte for underflows and either 2 or 1 byte per pixel # for the data npixelb = [int(e) for e in self.header_dict['NPIXELB'].split()] assert npixelb[1] == 1 if npixelb[0] == 1: read_data = read_uint8 elif npixelb[0] == 2: read_data = read_2b else: from dxtbx import IncorrectFormatError raise IncorrectFormatError( "{0} bytes per pixel is not supported".format(npixelb[0])) nrows = int(self.header_dict['NROWS'].split()[0]) ncols = int(self.header_dict['NCOLS'].split()[0]) raw_data = read_data(streambuf(f), nrows * ncols) image_size = (nrows, ncols) raw_data.reshape(flex.grid(*image_size)) (num_underflows, num_2b_overflows, num_4b_overflows) = [ int(e) for e in self.header_dict['NOVERFL'].split() ] # read underflows if num_underflows > 0: # stored values are padded to a multiple of 16 bytes nbytes = num_underflows + 15 & ~(15) underflow_vals = read_uint8(streambuf(f), nbytes)[:num_underflows] else: underflow_vals = None # handle 2 byte overflows if num_2b_overflows > 0: # stored values are padded to a multiple of 16 bytes nbytes = num_2b_overflows * 2 + 15 & ~(15) overflow_vals = read_2b(streambuf(f), nbytes // 2)[:num_2b_overflows] overflow = flex.int(nrows * ncols, 0) sel = (raw_data == 255).as_1d() overflow.set_selected(sel, overflow_vals - 255) overflow.reshape(flex.grid(*image_size)) raw_data += overflow # handle 4 byte overflows if num_4b_overflows > 0: # stored values are padded to a multiple of 16 bytes nbytes = num_4b_overflows * 4 + 15 & ~(15) overflow_vals = read_4b(streambuf(f), nbytes // 4)[:num_4b_overflows] overflow = flex.int(nrows * ncols, 0) sel = (raw_data == 65535).as_1d() overflow.set_selected(sel, overflow_vals - 65535) overflow.reshape(flex.grid(*image_size)) raw_data += overflow # handle underflows if underflow_vals is not None: sel = (raw_data == 0).as_1d() underflow = flex.int(nrows * ncols, 0) underflow.set_selected(sel, underflow_vals) underflow.reshape(flex.grid(*image_size)) raw_data += underflow # handle baseline. num_underflows == -1 means no baseline subtraction. See # https://github.com/cctbx/cctbx_project/files/1262952/BISFrameFileFormats.zip if num_underflows != -1: num_exposures = [int(e) for e in self.header_dict['NEXP'].split()] baseline = num_exposures[2] raw_data += baseline return raw_data