def _start(self): """Open the image file, read the image header, copy it into a dictionary for future reference.""" FormatCBF._start(self) cif_header = FormatCBF.get_cbf_header(self._image_file) self._cif_header_dictionary = {} for record in cif_header.split("\n"): if record[:1] != "#": continue if len(record[1:].split()) <= 2 and record.count(":") == 2: self._cif_header_dictionary["timestamp"] = record[1:].strip() continue tokens = record.replace("=", "").replace(":", "").split() self._cif_header_dictionary[tokens[1]] = " ".join(tokens[2:]) for record in self._mime_header.split("\n"): if not record.strip(): continue token, value = record.split(":") self._cif_header_dictionary[token.strip()] = value.strip()
def _start(self): '''Open the image file, read the image header, copy it into a dictionary for future reference.''' FormatCBF._start(self) cif_header = FormatCBF.get_cbf_header(self._image_file) self._cif_header_dictionary = { } for record in cif_header.split('\n'): if not '#' in record[:1]: continue if len(record[1:].split()) <= 2 and record.count(':') == 2: self._cif_header_dictionary['timestamp'] = record[1:].strip() continue tokens = record.replace('=', '').replace(':', '').split()[1:] self._cif_header_dictionary[tokens[0]] = ' '.join(tokens[1:]) for record in self._mime_header.split('\n'): if not record.strip(): continue token, value = record.split(':') self._cif_header_dictionary[token.strip()] = value.strip() return
def _start(self): '''Open the image file, read the image header, copy it into a dictionary for future reference.''' FormatCBF._start(self) cif_header = FormatCBF.get_cbf_header(self._image_file) self._cif_header_dictionary = {} for record in cif_header.split('\n'): if not '#' in record[:1]: continue if len(record[1:].split()) <= 2 and record.count(':') == 2: self._cif_header_dictionary['timestamp'] = record[1:].strip() continue tokens = record.replace('=', '').replace(':', '').split()[1:] self._cif_header_dictionary[tokens[0]] = ' '.join(tokens[1:]) for record in self._mime_header.split('\n'): if not record.strip(): continue token, value = record.split(':') self._cif_header_dictionary[token.strip()] = value.strip() return
def __init__(self, image_file, **kwargs): '''Initialise the image structure from the given file.''' assert(self.understand(image_file)) FormatCBF.__init__(self, image_file, **kwargs) return
def _start(self): '''Open the image file as a cbf file handle, and keep this somewhere safe.''' FormatCBF._start(self) from iotbx.detectors.cbf import CBFImage self.detectorbase = CBFImage(self._image_file) self.detectorbase.readHeader()
def __init__(self, image_file, **kwargs): '''Initialise the image structure from the given file.''' # It appears Pycbf can not handle unicode filenames (see dials/dials#256) image_file = str(image_file) assert (self.understand(image_file)) FormatCBF.__init__(self, image_file, **kwargs) return
def __init__(self, image_file, **kwargs): '''Initialise the image structure from the given file.''' # It appears Pycbf can not handle unicode filenames (see dials/dials#256) image_file = str(image_file) from dxtbx import IncorrectFormatError if not self.understand(image_file): raise IncorrectFormatError(self, image_file) FormatCBF.__init__(self, image_file, **kwargs) self._raw_data = None
def __init__(self, image_file, **kwargs): """Initialise the image structure from the given file.""" from dxtbx import IncorrectFormatError if not self.understand(image_file): raise IncorrectFormatError(self, image_file) FormatCBF.__init__(self, image_file, **kwargs) self._raw_data = None
def _start(self): """Read the image header and copy it into a dictionary for future reference. In this case the header is useless, so we populate the dictionary manually with dummy values""" FormatCBF._start(self) self._cif_header_dictionary = {} self._cif_header_dictionary["Detector_distance"] = "3.523 m" self._cif_header_dictionary["Beam_xy"] = "(1024.0, 1024.0) pixels" self._cif_header_dictionary["Wavelength"] = "0.02508 A" self._cif_header_dictionary["Pixel_size"] = "30e-6 m x 30e-6 m" self._cif_header_dictionary["X-Binary-Size-Fastest-Dimension"] = "2048" self._cif_header_dictionary["X-Binary-Size-Second-Dimension"] = "2048" self._cif_header_dictionary["Count_cutoff"] = "65535 counts" self._cif_header_dictionary["Phi"] = "0.0000 deg."
def understand(image_file): """Check to see if this looks like an CBF format image, i.e. we can make sense of it.""" header = FormatCBF.get_cbf_header(image_file) if "_diffrn.id" in header and "_diffrn_source" in header: return False def one_of_these_in(record): these = [ "PILATUS", "SLS", "SSRL", "?", "XDS special", "GENERIC_MINI", # intended for simulated PAD data, non-Pilatus array size ] for convention in these: if convention in record: return True return False for record in header.split("\n"): if "_array_data.header_convention" in record and one_of_these_in(record): return True if "# Detector" in record and "PILATUS" in record: # CBFlib v0.8.0 allowed return True if "# Detector" in record and "ADSC" in record and "HF-4M" in header: return True return False
def understand(image_file): '''Check to see if this looks like an CBF format image, i.e. we can make sense of it.''' header = FormatCBF.get_cbf_header(image_file) if '_diffrn.id' in header and '_diffrn_source' in header: return False for record in header.split('\n'): if '_array_data.header_convention' in record and \ 'PILATUS' in record: return True if '_array_data.header_convention' in record and \ 'SLS' in record: return True if '_array_data.header_convention' in record and \ '?' in record: return True if '# Detector' in record and \ 'PILATUS' in record: #CBFlib v0.8.0 allowed return True if '# Detector' in record and \ 'ADSC' in record and 'HF-4M' in header: return True return False
def understand(image_file): """Check to see if this looks like an CBF format image, i.e. we can make sense of it.""" header = FormatCBF.get_cbf_header(image_file) if "_diffrn.id" not in header and "_diffrn_source" not in header: return False # According to ImageCIF, "Data items in the DIFFRN_MEASUREMENT_AXIS # category associate axes with goniometers." # http://www.iucr.org/__data/iucr/cifdic_html/2/cif_img.dic/Cdiffrn_measurement_axis.html if "diffrn_measurement_axis" in header: return False # This implementation only supports single panel. try: cbf_handle = pycbf.cbf_handle_struct() cbf_handle.read_widefile(image_file.encode(), pycbf.MSG_DIGEST) except Exception as e: if "CBFlib Error" in str(e): return False # check if multiple arrays try: return cbf_handle.count_elements() == 1 except Exception as e: if "CBFlib Error" in str(e): return False return True
def understand(image_file): '''Check to see if this looks like an CBF format image, i.e. we can make sense of it.''' header = FormatCBF.get_cbf_header(image_file) if '_diffrn.id' in header and '_diffrn_source' in header: return False def one_of_these_in(record): these = [ 'PILATUS', 'SLS', 'SSRL', '?', 'XDS special', 'GENERIC_MINI', # intended for simulated PAD data, non-Pilatus array size ] for convention in these: if convention in record: return True return False for record in header.split('\n'): if '_array_data.header_convention' in record and one_of_these_in( record): return True if '# Detector' in record and \ 'PILATUS' in record: #CBFlib v0.8.0 allowed return True if '# Detector' in record and \ 'ADSC' in record and 'HF-4M' in header: return True return False
def understand(image_file): """Check to see if this looks like an CBF format image, i.e. we can make sense of it.""" header = FormatCBF.get_cbf_header(image_file) if "_diffrn.id" not in header and "_diffrn_source" not in header: return False return True
def understand(image_file): '''Check to see if this looks like an CBF format image, i.e. we can make sense of it.''' header = FormatCBF.get_cbf_header(image_file) if not '_diffrn.id' in header and not '_diffrn_source' in header: return False return True
def extract_header(self, cbf_filepath, npy_dir, bg=False): '''Assume all headers (mostly) the same for a directory of image files (i.e directory contains data from single aquisition experiment) :param str cbf_filepath: path to cbf image :param str npy_dir: path to destination :param bool bg: if True, add 'background' to file name ''' header = open( os.path.join(npy_dir, "{}header.txt".format("bg" if bg else "")), "w") header.write(FormatCBF.get_cbf_header(cbf_filepath)) header.close()
def get_image_key(self, cbf_filepath, npy_filepath): '''Keep the original image path from the header of each image as a means of tracing data back to original image data. :param str cbf_filepath: cbf image path :param str npy_filepath: new numpy image path :returns: string containing npy path followed by ramdisk path ''' cbf_filedir, cbf_filename = os.path.split(cbf_filepath) key = 'Image_path' head = FormatCBF.get_cbf_header(cbf_filepath) value = read_header(head, [key], file_string=True) ans = os.path.join(value['Image_path'][0], cbf_filename) return '{} {}'.format(npy_filepath, ans)
def understand(image_file): """Check to see if this looks like an CBF format image, i.e. we can make sense of it.""" header = FormatCBF.get_cbf_header(image_file) # The header is minimal, but we want to avoid 'understanding' CBFs from # other detectors. Use whatever we can in the header that might uniquely # identify the right images if "data_clip:_flipx" not in header: return False if "_array_data.header_convention" in header: return False if "Detector" in header: return False return True
def understand(image_file): '''Check to see if this looks like an CBF format image, i.e. we can make sense of it.''' header = FormatCBF.get_cbf_header(image_file) if not '_diffrn.id' in header and not '_diffrn_source': return False # According to ImageCIF, "Data items in the DIFFRN_MEASUREMENT_AXIS # category associate axes with goniometers." # http://www.iucr.org/__data/iucr/cifdic_html/2/cif_img.dic/Cdiffrn_measurement_axis.html if 'diffrn_measurement_axis' in header: return False # This implementation only supports single panel. try: cbf_handle = pycbf.cbf_handle_struct() cbf_handle.read_widefile(image_file, pycbf.MSG_DIGEST) except Exception, e: if 'CBFlib Error' in str(e): return False
def _get_cbf_handle(self): try: return self._cbf_handle except AttributeError: self._cbf_handle = pycbf.cbf_handle_struct() buffer = None # Reopen to tell if it's a gzip - this should be cached, so fast with FormatCBF.open_file(self._image_file, "rb") as fin: # If this was a gzip or bzip file, read as a buffer if (gzip and isinstance(fin._cache_object._file, gzip.GzipFile) ) or (bz2 and isinstance(fin._cache_object._file, bz2.BZ2File)): buffer = fin.read() if buffer: cbf_read_buffer(self._cbf_handle, buffer, pycbf.MSG_DIGEST) else: self._cbf_handle.read_widefile(self._image_file.encode(), pycbf.MSG_DIGEST) return self._cbf_handle
def _start(self): '''Open the image file as a cbf file handle, and keep this somewhere safe.''' FormatCBF._start(self)
def _start(self): """Open the image file as a cbf file handle, and keep this somewhere safe.""" FormatCBF._start(self) # Note, skip up an inheritance level
def _start(self): """Open the image file as a cbf file handle, and keep this somewhere safe.""" FormatCBF._start(self)
def _start(self): """Open the image file as a cbf file handle, and keep this somewhere safe.""" from dxtbx.format.FormatCBF import FormatCBF FormatCBF._start(self) # Note, skip up an inhieritance level
def _start(self): '''Open the image file as a cbf file handle, and keep this somewhere safe.''' from dxtbx.format.FormatCBF import FormatCBF FormatCBF._start(self) # Note, skip up an inhieritance level