Esempio n. 1
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
Esempio n. 2
0
def run_signal_strength_core(params, E):
    from spotfinder.applications.wrappers import DistlOrganizer

    verbosity = params.distl.verbosity
    if params.distl.res.inner != None:
        params.distl_lowres_limit = params.distl.res.inner
    if params.distl.res.outer != None:
        params.force_method2_resolution_limit = params.distl.res.outer
        params.distl_highres_limit = params.distl.res.outer

    params.distl_force_binning = False
    params.distl_permit_binning = False
    params.wedgelimit = len(E.argv)
    params.spotfinder_header_tests = False
    Org = DistlOrganizer(verbose=(verbosity > 1), argument_module=E, phil_params=params)
    Org.printSpots()
    return Org
Esempio n. 3
0
def run_signal_strength_core(params,E):
  from spotfinder.applications.wrappers import DistlOrganizer
  verbosity = params.distl.verbosity
  if params.distl.res.inner!=None:
    params.distl_lowres_limit = params.distl.res.inner
  if params.distl.res.outer!=None:
    params.force_method2_resolution_limit = params.distl.res.outer
    params.distl_highres_limit = params.distl.res.outer

  params.distl_force_binning = False
  params.distl_permit_binning = False
  params.wedgelimit = len(E.argv)
  params.spotfinder_header_tests = False
  Org = DistlOrganizer(verbose=(verbosity>1), argument_module=E,
                       phil_params=params)
  Org.printSpots()
  return Org
Esempio n. 4
0
  def __init__(self,params):
    E = Empty()
    E.argv=['Empty']
    E.argv.append(params.distl.image)

    self.verbose = params.distl.verbose
    if params.distl.res.inner!=None:
      params.distl_lowres_limit = params.distl.res.inner
    if params.distl.res.outer!=None:
      params.force_method2_resolution_limit = params.distl.res.outer
      params.distl_highres_limit = params.distl.res.outer

    params.distl_force_binning = False
    params.distl_permit_binning = False
    params.wedgelimit = len(E.argv)
    params.spotfinder_header_tests = False
    DistlOrganizer.__init__(self,verbose = True, argument_module=E,
                         phil_params=params)
    self.S = None # need to initialize determined by class SpotFrame
Esempio n. 5
0
    def __init__(self, params):
        E = Empty()
        E.argv = ['Empty']
        E.argv.append(params.distl.image)

        self.verbose = params.distl.verbose
        if params.distl.res.inner != None:
            params.distl_lowres_limit = params.distl.res.inner
        if params.distl.res.outer != None:
            params.force_method2_resolution_limit = params.distl.res.outer
            params.distl_highres_limit = params.distl.res.outer

        params.distl_force_binning = False
        params.distl_permit_binning = False
        params.wedgelimit = len(E.argv)
        params.spotfinder_header_tests = False
        DistlOrganizer.__init__(self,
                                verbose=True,
                                argument_module=E,
                                phil_params=params)
        self.S = None  # need to initialize determined by class SpotFrame
Esempio n. 6
0
def run_signal_strength_core(params,E):
  verbose = params.distl.verbose
  if params.distl.res.inner!=None:
    params.distl_lowres_limit = params.distl.res.inner
  if params.distl.res.outer!=None:
    params.force_method2_resolution_limit = params.distl.res.outer
    params.distl_highres_limit = params.distl.res.outer

  params.distl_force_binning = False
  params.distl_permit_binning = False
  params.wedgelimit = len(E.argv)
  params.spotfinder_header_tests = False
  Org = DistlOrganizer(verbose = True, argument_module=E,
                       phil_params=params)
  Org.printSpots()

  #Image analysis requested by NE-CAT (Point of contact: Craig Ogata)
  for key in Org.S.images.keys():
    # List of spots between specified high- and low-resolution limits
    if Org.S.images[key].has_key('lo_pass_resolution_spots'):
      spots = Org.S.images[key]['lo_pass_resolution_spots']
    elif Org.S.images[key].has_key('inlier_spots'):
      spots = Org.S.images[key]['inlier_spots']
    else:
      spots = []

    saturation = Org.Files.imageindex(key).saturation

    #Total number of spots in this range
    print
    print "Number of focus spots on image #%d within the input resolution range: %d"%(
      key,len(spots))

    signals=flex.double()
    saturations=flex.double()

    #Each spot
    for i,spot in enumerate(spots):
     signals.append(flex.sum(spot.wts))
     saturations.append(flex.max(spot.wts)/saturation)
     if verbose:
      #peak height given in ADC units above local background
      #integrated signal strength given in pixel-ADC units above local background
      print "%2d: Area in pixels=%d Peak=%.1f, Total integrated signal=%.1f (in pixel-ADC units above background)"%(
        i, spot.area(), flex.max(spot.wts), flex.sum(spot.wts))

      #peak signal-to-noise expressed in standard deviations above local background
      print "    Peak signal-to-noise=%.1f"%(spot.intensity())

      #peak height expressed in ADC units, without background subtraction
      image = Org.Files.imageindex(key)
      print "    Peak position x=%4d y=%4d (pixels); pixel value=%5d"%(
        spot.max_pxl_x(), spot.max_pxl_y(),
        image.linearintdata[(spot.max_pxl_x(),spot.max_pxl_y())])

      #Gory detail, looping through each pixel on each spot
      for j,pixel in enumerate(spot.bodypixels):
        print "       body pixel x=%4d y=%4d; pixel value=%5d; ADC height above background=%.1f"%(
          pixel.x,pixel.y,image.linearintdata[(pixel.x,pixel.y)],spot.wts[j])
    if signals.size()>0:
      print "Total integrated signal, pixel-ADC units above local background (just the good Bragg candidates) %d"%(
            flex.sum(flex.double([flex.sum(spot.wts) for spot in Org.S.images[key]['inlier_spots']]))
      )
      print "Signals range from %.1f to %.1f with mean integrated signal %.1f"%(
      flex.min(signals), flex.max(signals), flex.mean(signals) )
      print "Saturations range from %.1f%% to %.1f%% with mean saturation %.1f%%"%(
      100.*flex.min(saturations), 100.*flex.max(saturations), 100.*flex.mean(saturations) )

  if params.distl.pdf_output != None:
    #later, put this in a separate module so reportlab is not imported unless requested
    from labelit.publications.sublattice.sublattice_pdf import SublatticePDF,graphic
    from labelit.publications.sublattice.sublattice_pdf import PointTransform
    class genPDF(SublatticePDF):
      def make_image_plots_detail(self):
         params.pdf_output.window_fraction=1.0
         params.pdf_output.window_offset_x=0.0
         params.pdf_output.window_offset_y=0.0
         params.pdf_output.markup_inliers=True
         couple=(params.pdf_output.window_offset_x,
                 params.pdf_output.window_offset_y)
         #instead of self.R.setTransform, which requires pickled spotfinder:
         self.R.T = PointTransform()
         self.R.S = self.R.spotfinder
         self.R.T.setImage(spotfinder=self.R.S,subwindow_origin=couple,commands=params)
         self.R.title(self.image_name)
         #try:
         pil_image = graphic(filein = self.image_name,
                             couple = couple,
                             commands = params)
         self.R.image(pil_image)
         #except:
         #  print "failure, file %s"%self.filename
         if params.pdf_output.markup_inliers:
           self.R.show_ellipse(
           image_number=self.R.spotfinder.images.keys()[0],
           tags = ['goodspots','spots_non-ice','hi_pass_resolution_spots',
                    'spots_unimodal'],
           detail=True)
         self.R.c.showPage()
         return self
    pdf = genPDF(params.distl.pdf_output)
    pdf.filename = params.distl.pdf_output
    pdf.image_name = params.distl.image
    pdf.set_spotfinder(Org.S)
    pdf.make_image_plots_detail()

  if params.distl.image_viewer == True:
    try:
      from rstbx.viewer.spotfinder_wrap import spot_wrapper
      spot_wrapper(params).display(path = params.distl.image,
                                   organizer = Org)
    except ImportError,e:
      from libtbx.utils import Sorry
      # must use phenix.wxpython for wx display
      raise Sorry(str(e)+" Try setting env variable PHENIX_GUI_ENVIRONMENT=1")
Esempio n. 7
0
def run_signal_strength_core(params, E):
    verbose = params.distl.verbose
    if params.distl.res.inner != None:
        params.distl_lowres_limit = params.distl.res.inner
    if params.distl.res.outer != None:
        params.force_method2_resolution_limit = params.distl.res.outer
        params.distl_highres_limit = params.distl.res.outer

    params.distl_force_binning = False
    params.distl_permit_binning = False
    params.wedgelimit = len(E.argv)
    params.spotfinder_header_tests = False
    Org = DistlOrganizer(verbose=True, argument_module=E, phil_params=params)
    Org.printSpots()

    #Image analysis requested by NE-CAT (Point of contact: Craig Ogata)
    for key in Org.S.images.keys():
        # List of spots between specified high- and low-resolution limits
        if Org.S.images[key].has_key('lo_pass_resolution_spots'):
            spots = Org.S.images[key]['lo_pass_resolution_spots']
        elif Org.S.images[key].has_key('inlier_spots'):
            spots = Org.S.images[key]['inlier_spots']
        else:
            spots = []

        saturation = Org.Files.imageindex(key).saturation

        #Total number of spots in this range
        print
        print "Number of focus spots on image #%d within the input resolution range: %d" % (
            key, len(spots))

        signals = flex.double()
        saturations = flex.double()

        #Each spot
        for i, spot in enumerate(spots):
            signals.append(flex.sum(spot.wts))
            saturations.append(flex.max(spot.wts) / saturation)
            if verbose:
                #peak height given in ADC units above local background
                #integrated signal strength given in pixel-ADC units above local background
                print "%2d: Area in pixels=%d Peak=%.1f, Total integrated signal=%.1f (in pixel-ADC units above background)" % (
                    i, spot.area(), flex.max(spot.wts), flex.sum(spot.wts))

                #peak signal-to-noise expressed in standard deviations above local background
                print "    Peak signal-to-noise=%.1f" % (spot.intensity())

                #peak height expressed in ADC units, without background subtraction
                image = Org.Files.imageindex(key)
                print "    Peak position x=%4d y=%4d (pixels); pixel value=%5d" % (
                    spot.max_pxl_x(), spot.max_pxl_y(),
                    image.linearintdata[(spot.max_pxl_x(), spot.max_pxl_y())])

                #Gory detail, looping through each pixel on each spot
                for j, pixel in enumerate(spot.bodypixels):
                    print "       body pixel x=%4d y=%4d; pixel value=%5d; ADC height above background=%.1f" % (
                        pixel.x, pixel.y,
                        image.linearintdata[(pixel.x, pixel.y)], spot.wts[j])
        if signals.size() > 0:
            print "Total integrated signal, pixel-ADC units above local background (just the good Bragg candidates) %d" % (
                flex.sum(
                    flex.double([
                        flex.sum(spot.wts)
                        for spot in Org.S.images[key]['inlier_spots']
                    ])))
            print "Signals range from %.1f to %.1f with mean integrated signal %.1f" % (
                flex.min(signals), flex.max(signals), flex.mean(signals))
            print "Saturations range from %.1f%% to %.1f%% with mean saturation %.1f%%" % (
                100. * flex.min(saturations), 100. * flex.max(saturations),
                100. * flex.mean(saturations))

    if params.distl.pdf_output != None:
        #later, put this in a separate module so reportlab is not imported unless requested
        from labelit.publications.sublattice.sublattice_pdf import SublatticePDF, graphic
        from labelit.publications.sublattice.sublattice_pdf import PointTransform

        class genPDF(SublatticePDF):
            def make_image_plots_detail(self):
                params.pdf_output.window_fraction = 1.0
                params.pdf_output.window_offset_x = 0.0
                params.pdf_output.window_offset_y = 0.0
                params.pdf_output.markup_inliers = True
                couple = (params.pdf_output.window_offset_x,
                          params.pdf_output.window_offset_y)
                #instead of self.R.setTransform, which requires pickled spotfinder:
                self.R.T = PointTransform()
                self.R.S = self.R.spotfinder
                self.R.T.setImage(spotfinder=self.R.S,
                                  subwindow_origin=couple,
                                  commands=params)
                self.R.title(self.image_name)
                #try:
                pil_image = graphic(filein=self.image_name,
                                    couple=couple,
                                    commands=params)
                self.R.image(pil_image)
                #except:
                #  print "failure, file %s"%self.filename
                if params.pdf_output.markup_inliers:
                    self.R.show_ellipse(
                        image_number=self.R.spotfinder.images.keys()[0],
                        tags=[
                            'goodspots', 'spots_non-ice',
                            'hi_pass_resolution_spots', 'spots_unimodal'
                        ],
                        detail=True)
                self.R.c.showPage()
                return self

        pdf = genPDF(params.distl.pdf_output)
        pdf.filename = params.distl.pdf_output
        pdf.image_name = params.distl.image
        pdf.set_spotfinder(Org.S)
        pdf.make_image_plots_detail()

    if params.distl.image_viewer == True:
        try:
            from rstbx.viewer.spotfinder_wrap import spot_wrapper
            spot_wrapper(params).display(path=params.distl.image,
                                         organizer=Org)
        except ImportError, e:
            from libtbx.utils import Sorry
            # must use phenix.wxpython for wx display
            raise Sorry(
                str(e) + " Try setting env variable PHENIX_GUI_ENVIRONMENT=1")