コード例 #1
0
class FormatSMVADSCNoDateStamp(FormatSMVADSC):
    """A class for reading SMV format ADSC images, with detector serial number"""
    @staticmethod
    def understand(image_file):

        # assert for this that the image file has to be a file not a URL
        if not os.path.exists(image_file):
            return False

        size, header = FormatSMVADSC.get_smv_header(image_file)

        wanted_header_items = ["TIME"]
        if any(item not in header for item in wanted_header_items):
            return False

        unwanted_header_items = ["DATE"]

        if any(item in header for item in unwanted_header_items):
            return False

        return True

    def __init__(self, image_file, **kwargs):
        """Initialise the image structure from the given file, including a
        proper model of the experiment."""

        from dxtbx import IncorrectFormatError

        if not self.understand(image_file):
            raise IncorrectFormatError(self, image_file)

        FormatSMVADSC.__init__(self, image_file, **kwargs)

    def _start(self):

        FormatSMVADSC._start(self)

    def _scan(self):
        """Return the scan information for this image, using the timestamp
        from the file rather than the header."""

        format = self._scan_factory.format("SMV")
        exposure_time = float(self._header_dictionary["TIME"])

        epoch = float(os.stat(self._image_file)[8])

        osc_start = float(self._header_dictionary["OSC_START"])
        osc_range = float(self._header_dictionary["OSC_RANGE"])

        return self._scan_factory.single(self._image_file, format,
                                         exposure_time, osc_start, osc_range,
                                         epoch)

    def detectorbase_start(self):
        from iotbx.detectors.adsc import ADSCImage

        self.detectorbase = ADSCImage(self._image_file)
        self.detectorbase.open_file = self.open_file
        self.detectorbase.readHeader()
コード例 #2
0
    def readHeader(self):
        ADSCImage.readHeader(self,
                             external_keys=[("DETECTOR_NAME", "DETECTOR_NAME",
                                             str)])
        assert self.parameters["DETECTOR_NAME"].lower().find("hamamatsu") >= 0

        #above code validates the Hamamatsu signature, as in
        """HEADER_BYTES=512;
コード例 #3
0
ファイル: adsc_module.py プロジェクト: cctbx/cctbx-playground
def ADSC_module_from_file_url(url):
  #backward compatibility with Python 2.5
  try: from urlparse import parse_qs
  except Exception: from cgi import parse_qs

  from urlparse import urlparse
  parsed = urlparse(url)
  assert parsed.scheme == "file"
  file = parsed.path.split("?")[0]
  if file == parsed.path:
    return ADSCImage(file)
  qs = parse_qs(parsed.path.split("?")[1])
  sliceindex = int(qs["slice"][0])
  object = ADSCImage(file)
  object.readHeader()
  return ADSC_module_from_object_and_slicenumber(object,sliceindex)
コード例 #4
0
def ADSC_module_from_file_url(url):
    #backward compatibility with Python 2.5
    try:
        from urlparse import parse_qs
    except Exception:
        from cgi import parse_qs

    from urlparse import urlparse
    parsed = urlparse(url)
    assert parsed.scheme == "file"
    file = parsed.path.split("?")[0]
    if file == parsed.path:
        return ADSCImage(file)
    qs = parse_qs(parsed.path.split("?")[1])
    sliceindex = int(qs["slice"][0])
    object = ADSCImage(file)
    object.readHeader()
    return ADSC_module_from_object_and_slicenumber(object, sliceindex)
コード例 #5
0
class FormatSMVADSCNoDateStamp(FormatSMVADSC):
    """A class for reading SMV format ADSC images, with detector serial number"""

    @staticmethod
    def understand(image_file):

        # assert for this that the image file has to be a file not a URL
        if not os.path.exists(image_file):
            return False

        size, header = FormatSMVADSC.get_smv_header(image_file)

        wanted_header_items = ["TIME"]
        if any(item not in header for item in wanted_header_items):
            return False

        unwanted_header_items = ["DATE"]

        if any(item in header for item in unwanted_header_items):
            return False

        return True

    def _scan(self):
        """Return the scan information for this image, using the timestamp
        from the file rather than the header."""

        exposure_time = float(self._header_dictionary["TIME"])

        epoch = float(os.stat(self._image_file)[8])

        osc_start = float(self._header_dictionary["OSC_START"])
        osc_range = float(self._header_dictionary["OSC_RANGE"])

        return self._scan_factory.single_file(
            self._image_file, exposure_time, osc_start, osc_range, epoch
        )

    def detectorbase_start(self):
        self.detectorbase = ADSCImage(self._image_file)
        self.detectorbase.open_file = self.open_file
        self.detectorbase.readHeader()
コード例 #6
0
class FormatSMVADSCSN(FormatSMVADSC):
  '''A class for reading SMV format ADSC images, with detector serial number'''

  @staticmethod
  def understand(image_file):
    # The header must include a DATE and an integer-valued DETECTOR_SN
    # for this format to apply.

    size, header = FormatSMVADSC.get_smv_header(image_file)

    if 'DATE' not in header.keys():
      return False
    try:
      int(header['DETECTOR_SN'])
    except (KeyError, ValueError):
      return False

    return True

  def __init__(self, image_file, **kwargs):
    '''Initialise the image structure from the given file, including a
    proper model of the experiment.'''

    from dxtbx import IncorrectFormatError
    if not self.understand(image_file):
      raise IncorrectFormatError(self, image_file)

    FormatSMVADSC.__init__(self, image_file, **kwargs)

    return

  def _start(self):

    FormatSMVADSC._start(self)

  def detectorbase_start(self):

    from iotbx.detectors.adsc import ADSCImage
    self.detectorbase = ADSCImage(self._image_file)
    self.detectorbase.open_file = self.open_file
    self.detectorbase.readHeader()
コード例 #7
0
class FormatSMVADSCSN(FormatSMVADSC):
  '''A class for reading SMV format ADSC images, with detector serial number'''

  @staticmethod
  def understand(image_file):
    # The header must include a DATE and an integer-valued DETECTOR_SN
    # for this format to apply.

    size, header = FormatSMVADSC.get_smv_header(image_file)

    if 'DATE' not in header.keys():
      return False
    try:
      int(header['DETECTOR_SN'])
    except (KeyError, ValueError):
      return False

    return True

  def __init__(self, image_file):
    '''Initialise the image structure from the given file, including a
    proper model of the experiment.'''

    assert(self.understand(image_file))

    FormatSMVADSC.__init__(self, image_file)

    return

  def _start(self):

    FormatSMVADSC._start(self)

  def detectorbase_start(self):

    from iotbx.detectors.adsc import ADSCImage
    self.detectorbase = ADSCImage(self._image_file)
    self.detectorbase.readHeader()
コード例 #8
0
class FormatSMVADSCNoDateStamp(FormatSMVADSC):
    """A class for reading SMV format ADSC images, with detector serial number"""

    @staticmethod
    def understand(image_file):

        # assert for this that the image file has to be a file not a URL

        import os

        if not os.path.exists(image_file):
            return False

        size, header = FormatSMVADSC.get_smv_header(image_file)

        wanted_header_items = ["TIME"]

        for header_item in wanted_header_items:
            if not header_item in header:
                return False

        unwanted_header_items = ["DATE"]

        for header_item in unwanted_header_items:
            if header_item in header:
                return False

        return True

    def __init__(self, image_file):
        """Initialise the image structure from the given file, including a
    proper model of the experiment."""

        assert self.understand(image_file)

        FormatSMVADSC.__init__(self, image_file)

        return

    def _start(self):

        from iotbx.detectors.adsc import ADSCImage

        self.detectorbase = ADSCImage(self._image_file)
        self.detectorbase.readHeader()

        FormatSMVADSC._start(self)

    def _scan(self):
        """Return the scan information for this image, using the timestamp
    from the file rather than the header."""

        format = self._scan_factory.format("SMV")
        exposure_time = float(self._header_dictionary["TIME"])

        import os

        epoch = float(os.stat(self._image_file)[8])

        osc_start = float(self._header_dictionary["OSC_START"])
        osc_range = float(self._header_dictionary["OSC_RANGE"])

        return self._scan_factory.single(self._image_file, format, exposure_time, osc_start, osc_range, epoch)
コード例 #9
0
class FormatSMVADSCSN(FormatSMVADSC):
    """A class for reading SMV format ADSC images, with detector serial number"""
    @staticmethod
    def understand(image_file):
        # The header must include a DATE and an integer-valued DETECTOR_SN
        # for this format to apply.

        size, header = FormatSMVADSC.get_smv_header(image_file)

        if "DATE" not in header:
            return False
        try:
            int(header["DETECTOR_SN"])
        except (KeyError, ValueError):
            return False

        return True

    def __init__(self, image_file, **kwargs):
        """Initialise the image structure from the given file, including a
        proper model of the experiment."""

        # Mapping of serial numbers to models for known detectors
        self._sn_to_model = {
            401: "Q4U",
            402: "Q4",
            414: "Q4",
            423: "Q4R",
            428: "Q4R",
            429: "Q4",  # or Q4R?
            441: "Q210",
            442: "Q210",
            443: "Q210",
            444: "Q210",  # or Q210R?
            445: "Q210",
            446: "Q210",
            447: "Q210",
            448: "Q210",
            457: "Q210R",
            471: "Q270",
            472: "Q270",
            474: "Q270",
            901: "Q210",
            905: "Q315",
            907: "Q315R",  # or Q315?
            913: "Q315",
            917: "Q315R",
            923: "Q315R",
            925: "Q315",
            926: "Q315R",
            928: "Q315R",
            931: "Q315R",
            933: "Q315R",
        }

        super().__init__(image_file, **kwargs)

    def _adsc_module_gain(self, model=None):
        """Overload to look the model number up from the serial number table"""

        if model is None:
            sn = int(self._header_dictionary["DETECTOR_SN"])
            model = self._sn_to_model.get(sn)
        return super()._adsc_module_gain(model=model)

    def detectorbase_start(self):

        self.detectorbase = ADSCImage(self._image_file)
        self.detectorbase.open_file = self.open_file
        self.detectorbase.readHeader()
コード例 #10
0
ファイル: hamamatsu.py プロジェクト: cctbx/cctbx-playground
  def readHeader(self):
    ADSCImage.readHeader(self,external_keys=[("DETECTOR_NAME","DETECTOR_NAME",str)])
    assert self.parameters["DETECTOR_NAME"].lower().find("hamamatsu")>=0

    #above code validates the Hamamatsu signature, as in
    """HEADER_BYTES=512;
コード例 #11
0
class FormatSMVADSCNoDateStamp(FormatSMVADSC):
    '''A class for reading SMV format ADSC images, with detector serial number'''
    @staticmethod
    def understand(image_file):

        # assert for this that the image file has to be a file not a URL

        import os
        if not os.path.exists(image_file):
            return False

        size, header = FormatSMVADSC.get_smv_header(image_file)

        wanted_header_items = ['TIME']

        for header_item in wanted_header_items:
            if not header_item in header:
                return False

        unwanted_header_items = ['DATE']

        for header_item in unwanted_header_items:
            if header_item in header:
                return False

        return True

    def __init__(self, image_file, **kwargs):
        '''Initialise the image structure from the given file, including a
    proper model of the experiment.'''

        assert (self.understand(image_file))

        FormatSMVADSC.__init__(self, image_file, **kwargs)

        return

    def _start(self):

        FormatSMVADSC._start(self)

    def _scan(self):
        '''Return the scan information for this image, using the timestamp
    from the file rather than the header.'''

        format = self._scan_factory.format('SMV')
        exposure_time = float(self._header_dictionary['TIME'])

        import os
        epoch = float(os.stat(self._image_file)[8])

        osc_start = float(self._header_dictionary['OSC_START'])
        osc_range = float(self._header_dictionary['OSC_RANGE'])

        return self._scan_factory.single(self._image_file, format,
                                         exposure_time, osc_start, osc_range,
                                         epoch)

    def detectorbase_start(self):
        from iotbx.detectors.adsc import ADSCImage
        self.detectorbase = ADSCImage(self._image_file)
        self.detectorbase.readHeader()
コード例 #12
0
class FormatSMVADSCSN(FormatSMVADSC):
  '''A class for reading SMV format ADSC images, with detector serial number'''

  @staticmethod
  def understand(image_file):
    # The header must include a DATE and an integer-valued DETECTOR_SN
    # for this format to apply.

    size, header = FormatSMVADSC.get_smv_header(image_file)

    if 'DATE' not in header.keys():
      return False
    try:
      int(header['DETECTOR_SN'])
    except (KeyError, ValueError):
      return False

    return True

  def __init__(self, image_file, **kwargs):
    '''Initialise the image structure from the given file, including a
    proper model of the experiment.'''

    from dxtbx import IncorrectFormatError
    if not self.understand(image_file):
      raise IncorrectFormatError(self, image_file)

    # Mapping of serial numbers to models for known detectors
    self._sn_to_model = {401: 'Q4U',
                         402: 'Q4',
                         414: 'Q4',
                         423: 'Q4R',
                         428: 'Q4R',
                         429: 'Q4', # or Q4R?
                         441: 'Q210',
                         442: 'Q210',
                         443: 'Q210',
                         444: 'Q210', # or Q210R?
                         445: 'Q210',
                         446: 'Q210',
                         447: 'Q210',
                         448: 'Q210',
                         457: 'Q210R',
                         471: 'Q270',
                         472: 'Q270',
                         474: 'Q270',
                         901: 'Q210',
                         905: 'Q315',
                         907: 'Q315R', # or Q315?
                         913: 'Q315',
                         917: 'Q315R',
                         923: 'Q315R',
                         925: 'Q315',
                         926: 'Q315R',
                         928: 'Q315R',
                         931: 'Q315R',
                         933: 'Q315R',
                         }

    FormatSMVADSC.__init__(self, image_file, **kwargs)

  def _adsc_module_gain(self, model=None):
    '''Overload to look the model number up from the serial number table'''

    if model is None:
      sn = int(self._header_dictionary['DETECTOR_SN'])
      model = self._sn_to_model.get(sn)
    return super(FormatSMVADSCSN, self)._adsc_module_gain(model=model)

  def _start(self):

    FormatSMVADSC._start(self)

  def detectorbase_start(self):

    from iotbx.detectors.adsc import ADSCImage
    self.detectorbase = ADSCImage(self._image_file)
    self.detectorbase.open_file = self.open_file
    self.detectorbase.readHeader()