예제 #1
0
    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
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()
예제 #3
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;
예제 #4
0
  def _start(self):

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

    FormatSMVADSC._start(self)
예제 #5
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)
예제 #6
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)
예제 #7
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()
예제 #8
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()
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()
예제 #10
0
        if self.object.linearintdata.__dict__.get("bin2by2") == True:
            new_data_array.bin2by2 = True
        del self.object  #once the data are copied, no need to keep the original
        return new_data_array

    def read(self):
        if self.already_read_data: return
        self.bin_safe_set_data(self.slice_callback())
        self.already_read_data = True


if __name__ == '__main__':
    import sys
    sliceidx = 4
    full_path_to_file = sys.argv[1]
    a = ADSCImage(full_path_to_file)
    a.read()
    print(a)
    print(a.parameters)
    print(a.rawdata, len(a.rawdata), a.size1 * a.size2)
    for dataitem in [
            'bin', 'filename', 'header', 'headerlines', 'linearintdata',
            'parameters', 'vendortype'
    ]:
        print(dataitem, end=' ')
        exec("print a.%s" % dataitem)
    print(ADSC_module_from_object_and_slicenumber(a, sliceidx))

    P = ADSC_module_from_file_url(url="file://%s?slice=%d" %
                                  (full_path_to_file, sliceidx))
    print("file://%s?slice=%d" % (full_path_to_file, sliceidx))
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)
예제 #12
0
    ID = image_divider(data = self.object.linearintdata, nullvalue=nullvalue)
    assert 0 <= self.moduleindex < ID.module_count()
    new_data_array = ID.tile_data(self.moduleindex)
    if self.object.linearintdata.__dict__.get("bin2by2")==True:
      new_data_array.bin2by2=True
    del self.object #once the data are copied, no need to keep the original
    return new_data_array

  def read(self):
    if self.already_read_data: return
    self.bin_safe_set_data(self.slice_callback())
    self.already_read_data = True

if __name__=='__main__':
  import sys
  sliceidx=4
  full_path_to_file = sys.argv[1]
  a = ADSCImage(full_path_to_file)
  a.read()
  print a
  print a.parameters
  print a.rawdata, len(a.rawdata), a.size1*a.size2
  for dataitem in ['bin', 'filename', 'header', 'headerlines', 'linearintdata', 'parameters', 'vendortype']:
    print dataitem,
    exec("print a.%s"%dataitem)
  print ADSC_module_from_object_and_slicenumber(a,sliceidx)

  P = ADSC_module_from_file_url(url="file://%s?slice=%d"%(full_path_to_file,sliceidx))
  print "file://%s?slice=%d"%(full_path_to_file,sliceidx)
  print P
예제 #13
0
    def detectorbase_start(self):

        self.detectorbase = ADSCImage(self._image_file)
        self.detectorbase.open_file = self.open_file
        self.detectorbase.readHeader()
예제 #14
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()
예제 #15
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;
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()
예제 #17
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()