Beispiel #1
0
    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
Beispiel #2
0
    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
Beispiel #3
0
  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
Beispiel #4
0
    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 _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
Beispiel #6
0
    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
Beispiel #7
0
    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()
Beispiel #8
0
    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
Beispiel #10
0
    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
Beispiel #11
0
    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()
Beispiel #12
0
    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)
Beispiel #13
0
    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
Beispiel #14
0
  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