Example #1
0
def get_spot_convention(imagefile):
    # Maybe 2 if RAXIS else 0..
    return 2
    from spotfinder.command_line.signal_strength import master_params
    phil_params = master_params.extract()

    imageobject = iotbx.detectors.ImageFactory(G["file"][start_frame])

    beam_center_convention_from_image_object(imageobject, phil_params)

    print "SPOT CONVENTION=", phil_params.spot_convention

    return phil_params.spot_convention
Example #2
0
def get_spot_convention(imagefile):
    # Maybe 2 if RAXIS else 0..
    return 2
    from spotfinder.command_line.signal_strength import master_params
    phil_params = master_params.extract()

    imageobject = iotbx.detectors.ImageFactory(G["file"][start_frame])

    beam_center_convention_from_image_object(imageobject, phil_params)

    print "SPOT CONVENTION=", phil_params.spot_convention

    return phil_params.spot_convention
Example #3
0
  def triage_image(self):
    """ Performs a quick DISTL spotfinding without grid search.
        NOTE: Convert to DIALS spotfinder when ready! (Even for CCTBX runs.)
    """

    import spotfinder
    from spotfinder.command_line.signal_strength import master_params as sf_params
    from spotfinder.applications.wrappers import DistlOrganizer

    sf_params = sf_params.extract()
    sf_params.distl.image = self.conv_img

    E = Empty()
    E.argv=['Empty']
    E.argv.append(sf_params.distl.image)

    selected_output = []
    total_output = []
    bragg_spots = []
    spotfinding_log = ['{}\n'.format(self.conv_img)]

    # set spotfinding parameters for DISTL spotfinder
    sf_params.distl.minimum_spot_area = self.params.cctbx.grid_search.area_median
    sf_params.distl.minimum_spot_height = self.params.cctbx.grid_search.height_median
    sf_params.distl.minimum_signal_height = int(self.params.cctbx.grid_search.height_median / 2)

    # run DISTL spotfinder
    with misc.Capturing() as junk_output:
      Org = DistlOrganizer(verbose = False, argument_module=E,
                           phil_params=sf_params)

      Org.printSpots()

    # Extract relevant spotfinding info & make selection
    for frame in Org.S.images.keys():
      self.Bragg = Org.S.images[frame]['N_spots_inlier']

    if self.Bragg >= self.params.image_triage.min_Bragg_peaks:
      self.log_info.append('ACCEPTED! {} good Bragg peaks'\
                            ''.format(self.Bragg))
      status = None
    else:
      self.log_info.append('REJECTED')
      status = 'failed triage'

    return status
Example #4
0
    def __init__(self, file_name):
        screen_params.__init__(self)
        # XXX major hack - Boost.Python doesn't really deal with Unicode strings
        if isinstance(file_name, unicode):
            file_name = str(file_name)
        if isinstance(file_name, str) or isinstance(file_name, dict):
            self.file_name = file_name
            from iotbx.detectors import ImageFactory, ImageException
            try:
                img = ImageFactory(file_name)
            except ImageException as e:
                raise Sorry(str(e))
            img.read()
        else:
            img = file_name  # assume it's already been read

        self._raw = img
        try:
            img.show_header()
        except Exception:
            pass  # intentional

        detector = self._raw.get_detector()
        if len(detector) == 1:
            # Image size only makes sense for monolithic detectors.
            image_size = detector[0].get_image_size()
            self.set_image_size(w=image_size[0], h=image_size[1])

        pixel_size = detector[0].get_pixel_size()
        for panel in detector:
            pstest = panel.get_pixel_size()
            assert pixel_size[0] == pixel_size[1] == pstest[0] == pstest[1]
        self.set_detector_resolution(pixel_size[0])

        try:
            from spotfinder.command_line.signal_strength import master_params
            params = master_params.extract()
            self._raw.initialize_viewer_properties(params)
        except Exception:
            pass  # intentional

        self._beam_center = None
        self._integration = None
        self._spots = None
        self._color_scheme = None
Example #5
0
    if len(detector) == 1:
      # Image size only makes sense for monolithic detectors.
      image_size = detector[0].get_image_size()
      self.set_image_size(
        w=image_size[0],
        h=image_size[1])

    pixel_size = detector[0].get_pixel_size()
    for panel in detector:
      pstest = panel.get_pixel_size()
      assert pixel_size[0] == pixel_size[1] == pstest[0] == pstest[1]
    self.set_detector_resolution(pixel_size[0])

    try:
      from spotfinder.command_line.signal_strength import master_params
      params = master_params.extract()
      self._raw.initialize_viewer_properties(params)
    except Exception: pass # intentional

    self._beam_center = None
    self._integration = None
    self._spots = None
    self._color_scheme = None
    #self.update_image()
    #self.convert_to_bitmap()

  def set_integration_results (self, integration) :
    self._integration = integration
    mp = integration['mapped_predictions']
    print "%d spot predictions loaded" % mp.size()
    print "max. resolution is %g" % integration['resolution']
Example #6
0
    def triage_image(self):
        """ Performs a quick DISTL spotfinding without grid search.
    """
        from spotfinder.command_line.signal_strength import master_params as sf_params

        sf_params = sf_params.extract()
        sf_params.distl.image = self.img

        E = Empty()
        E.argv = ['Empty']
        E.argv.append(sf_params.distl.image)

        log_info = ['{}\n'.format(self.img)]
        img_filename = os.path.basename(self.img)

        # Perform spotfinding
        # ... using spotfinding grid search
        if self.params.image_triage.type == 'grid_search':
            log_info.append('\n CCTBX TRIAGE grid search:')
            # Determine grid search extent
            a_min = self.params.image_triage.grid_search.area_min
            a_max = self.params.image_triage.grid_search.area_max
            a_step = (a_max -
                      a_min) // self.params.image_triage.grid_search.step_size
            h_min = self.params.image_triage.grid_search.height_min
            h_max = self.params.image_triage.grid_search.height_max
            h_step = (h_max -
                      h_min) // self.params.image_triage.grid_search.step_size

            # Cycle through grid points
            spotlist = []
            for spa in range(a_min, a_max + 1, a_step):
                for sph in range(h_min, h_max + 1, h_step):
                    sf_params.distl.minimum_spot_area = spa
                    sf_params.distl.minimum_spot_height = sph
                    sf_params.distl.minimum_signal_height = sph

                    # Perform spotfinding
                    Bragg_spots = self.run_distl(sf_params)
                    N_Bragg_spots = len(Bragg_spots)

                    if N_Bragg_spots > 0:
                        total_intensity = flex.sum(flex.double(Bragg_spots))
                    else:
                        total_intensity = 0

                    spotlist.append({
                        'bragg': N_Bragg_spots,
                        'ti': total_intensity,
                        'spa': spa,
                        'sph': sph
                    })
                    log_info.append('{:<{w}}: H = {:<2}, A = {:<2}, Bragg = {:<6.0f}  '\
                                    'total intensity = {:<12.4f}'.format(img_filename, sph, spa,
                                    N_Bragg_spots, total_intensity, w = len(img_filename)))

            # Pick best spotfinding result (highest total intensity seems to work for now
            pick = sorted(spotlist, key=lambda j: j['ti'])[-1]
            N_Bragg_spots = pick['bragg']
            start_sph = pick['sph']
            start_sih = pick['sph']
            start_spa = pick['spa']

        # ... using spotfinding without grid search
        else:
            # Set spotfinding params
            sf_params.distl.minimum_spot_area = self.params.cctbx.grid_search.area_median
            sf_params.distl.minimum_spot_height = self.params.cctbx.grid_search.height_median
            sf_params.distl.minimum_signal_height = self.params.cctbx.grid_search.height_median

            # Perform spotfinding
            Bragg_spots = self.run_distl(sf_params)

            # Extract spotfinding results
            N_Bragg_spots = len(Bragg_spots)
            start_sph = self.params.cctbx.grid_search.height_median
            start_sih = self.params.cctbx.grid_search.height_median
            start_spa = self.params.cctbx.grid_search.area_median

        # Determine triage success
        if N_Bragg_spots >= self.params.image_triage.min_Bragg_peaks:
            log_info.append('ACCEPTED! Selected starting point:')
            log_info.append('{:<{w}}: S = {:<2}, H = {:<2}, A = {:<2}, Bragg = {:<6.0f}'\
                            ''.format(img_filename, start_sih, start_sph, start_spa,
                                      N_Bragg_spots, w = len(img_filename)))
            status = None
        else:
            log_info.append(
                'REJECTED! ({} Bragg peaks found)'.format(N_Bragg_spots))
            status = 'failed triage'

        log_entry = "\n".join(log_info)

        return status, log_entry, start_sph, start_spa
Example #7
0
    if len(detector) == 1:
      # Image size only makes sense for monolithic detectors.
      image_size = detector[0].get_image_size()
      self.set_image_size(
        w=image_size[0],
        h=image_size[1])

    pixel_size = detector[0].get_pixel_size()
    for panel in detector:
      pstest = panel.get_pixel_size()
      assert pixel_size[0] == pixel_size[1] == pstest[0] == pstest[1]
    self.set_detector_resolution(pixel_size[0])

    try:
      from spotfinder.command_line.signal_strength import master_params
      params = master_params.extract()
      self._raw.initialize_viewer_properties(params)
    except Exception: pass # intentional

    self._beam_center = None
    self._integration = None
    self._spots = None
    self._color_scheme = None
    #self.update_image()
    #self.convert_to_bitmap()

  def set_integration_results (self, integration) :
    self._integration = integration
    mp = integration['mapped_predictions']
    print "%d spot predictions loaded" % mp.size()
    print "max. resolution is %g" % integration['resolution']
  def triage_image(self):
    """ Performs a quick DISTL spotfinding without grid search.
    """
    from spotfinder.command_line.signal_strength import master_params as sf_params

    sf_params = sf_params.extract()
    sf_params.distl.image = self.img

    E = Empty()
    E.argv=['Empty']
    E.argv.append(sf_params.distl.image)

    log_info = ['{}\n'.format(self.img)]
    img_filename = os.path.basename(self.img)

    # Perform spotfinding
    # ... using spotfinding grid search
    if self.params.image_triage.type == 'grid_search':
      log_info.append('\n CCTBX TRIAGE grid search:')
      # Determine grid search extent
      a_min = self.params.image_triage.grid_search.area_min
      a_max = self.params.image_triage.grid_search.area_max
      a_step = (a_max - a_min) // self.params.image_triage.grid_search.step_size
      h_min = self.params.image_triage.grid_search.height_min
      h_max = self.params.image_triage.grid_search.height_max
      h_step = (h_max - h_min) // self.params.image_triage.grid_search.step_size

      # Cycle through grid points
      spotlist = []
      for spa in range(a_min, a_max + 1, a_step):
        for sph in range(h_min, h_max + 1, h_step):
          sf_params.distl.minimum_spot_area = spa
          sf_params.distl.minimum_spot_height = sph
          sf_params.distl.minimum_signal_height = sph

          # Perform spotfinding
          Bragg_spots = self.run_distl(sf_params)
          N_Bragg_spots = len(Bragg_spots)

          if N_Bragg_spots > 0:
            total_intensity = flex.sum(flex.double(Bragg_spots))
          else:
            total_intensity = 0

          spotlist.append({'bragg':N_Bragg_spots, 'ti':total_intensity,
                           'spa':spa, 'sph':sph})
          log_info.append('{:<{w}}: H = {:<2}, A = {:<2}, Bragg = {:<6.0f}  '\
                          'total intensity = {:<12.4f}'.format(img_filename, sph, spa,
                          N_Bragg_spots, total_intensity, w = len(img_filename)))

      # Pick best spotfinding result (highest total intensity seems to work for now
      pick = sorted(spotlist, key = lambda j: j['ti'])[-1]
      N_Bragg_spots = pick['bragg']
      start_sph = pick['sph']
      start_sih = pick['sph']
      start_spa = pick['spa']

    # ... using spotfinding without grid search
    else:
      # Set spotfinding params
      sf_params.distl.minimum_spot_area = self.params.cctbx.grid_search.area_median
      sf_params.distl.minimum_spot_height = self.params.cctbx.grid_search.height_median
      sf_params.distl.minimum_signal_height = self.params.cctbx.grid_search.height_median

      # Perform spotfinding
      Bragg_spots = self.run_distl(sf_params)

      # Extract spotfinding results
      N_Bragg_spots = len(Bragg_spots)
      start_sph = self.params.cctbx.grid_search.height_median
      start_sih = self.params.cctbx.grid_search.height_median
      start_spa = self.params.cctbx.grid_search.area_median

    # Determine triage success
    if N_Bragg_spots >= self.params.image_triage.min_Bragg_peaks:
      log_info.append('ACCEPTED! Selected starting point:')
      log_info.append('{:<{w}}: S = {:<2}, H = {:<2}, A = {:<2}, Bragg = {:<6.0f}'\
                      ''.format(img_filename, start_sih, start_sph, start_spa,
                                N_Bragg_spots, w = len(img_filename)))
      status = None
    else:
      log_info.append('REJECTED!')
      status = 'failed triage'

    log_entry = "\n".join(log_info)

    return status, log_entry, start_sph, start_spa