Example #1
0
 def background(self,spotfinder):
   self.addColumn('PxlBkgrd') # mean pixel background at center of windows in the shell
   self.PxlBkgrd.format = "%.1f"
   self.addColumn('MnWndwSz') # mean size (in pixels) of the scanbox windows in the shell
   self.MnWndwSz.format = "%.0f"
   for irow in xrange(self.S_table_rows):
     self.PxlBkgrd[irow] = flex.double()
     self.MnWndwSz[irow] = flex.double()
   sortedidx = flex.sort_permutation(spotfinder.background_resolutions(),reverse=True)
   reverse_resolutions = spotfinder.background_resolutions().select(sortedidx)
   reverse_backgrounds = spotfinder.background_means().select(sortedidx)
   reverse_wndw_sz = spotfinder.background_wndw_sz().select(sortedidx)
   row = 0
   for x in xrange(len(reverse_resolutions)):
     while reverse_resolutions[x] < self.Limit[row]:
       row += 1
       if row >= self.S_table_rows: break
     if row >= self.S_table_rows: break
     self.PxlBkgrd[row].append(reverse_backgrounds[x])
     self.MnWndwSz[row].append(reverse_wndw_sz[x])
   for irow in xrange(self.S_table_rows):
     #print irow, len(self.PxlBkgrd[irow])
     #print list(self.PxlBkgrd[irow])
     #print list(self.PxlSigma[irow])
     if len(self.PxlBkgrd[irow])==0: self.PxlBkgrd[irow]=None; continue #No analysis without mean background
     self.PxlBkgrd[irow] = flex.mean(self.PxlBkgrd[irow])
     self.MnWndwSz[irow] = flex.mean(self.MnWndwSz[irow])
Example #2
0
 def background(self, spotfinder):
     self.addColumn(
         'PxlBkgrd'
     )  # mean pixel background at center of windows in the shell
     self.PxlBkgrd.format = "%.1f"
     self.addColumn(
         'MnWndwSz'
     )  # mean size (in pixels) of the scanbox windows in the shell
     self.MnWndwSz.format = "%.0f"
     for irow in xrange(self.S_table_rows):
         self.PxlBkgrd[irow] = flex.double()
         self.MnWndwSz[irow] = flex.double()
     sortedidx = flex.sort_permutation(spotfinder.background_resolutions(),
                                       reverse=True)
     reverse_resolutions = spotfinder.background_resolutions().select(
         sortedidx)
     reverse_backgrounds = spotfinder.background_means().select(sortedidx)
     reverse_wndw_sz = spotfinder.background_wndw_sz().select(sortedidx)
     row = 0
     for x in xrange(len(reverse_resolutions)):
         while reverse_resolutions[x] < self.Limit[row]:
             row += 1
             if row >= self.S_table_rows: break
         if row >= self.S_table_rows: break
         self.PxlBkgrd[row].append(reverse_backgrounds[x])
         self.MnWndwSz[row].append(reverse_wndw_sz[x])
     for irow in xrange(self.S_table_rows):
         #print irow, len(self.PxlBkgrd[irow])
         #print list(self.PxlBkgrd[irow])
         #print list(self.PxlSigma[irow])
         if len(self.PxlBkgrd[irow]) == 0:
             self.PxlBkgrd[irow] = None
             continue  #No analysis without mean background
         self.PxlBkgrd[irow] = flex.mean(self.PxlBkgrd[irow])
         self.MnWndwSz[irow] = flex.mean(self.MnWndwSz[irow])
Example #3
0
    def sigma_analysis(self):
        #assumes that self.total_signal() and self.background() have already been called.
        self.addColumn('MeanIsigI',
                       0)  #mean I over sig(I) for spots within the shell
        self.MeanIsigI.format = "%.3f"
        index = 0
        for row in xrange(self.S_table_rows):
            if self.PxlBkgrd[row] == None: continue
            IsigI_values = flex.double()
            for idx in xrange(self.Population[row]):
                # Use International Tables Vol F (2001) equation 11.2.5.9 (p. 214)
                I_s = flex.sum(self.persist_fstats.master[
                    self.persist_indices[index]].wts)
                I_bg = flex.sum(self.persist_fstats.master[
                    self.persist_indices[index]].bkg)
                m_sz = len(self.persist_fstats.master[
                    self.persist_indices[index]].wts)
                n_sz = self.MnWndwSz[row]
                gain = 1.00

                spot_variance = gain * (I_s + I_bg + (m_sz * m_sz) *
                                        (1. / n_sz) * self.PxlBkgrd[row])

                IsigI_values.append(I_s / math.sqrt(spot_variance))

                index += 1
            if len(IsigI_values) > 0:
                self.MeanIsigI[row] = flex.mean(IsigI_values)
Example #4
0
 def get_resolution_inspection(self):
     all_frames = self.images.keys()
     all_resolutions = flex.double(
         [self.images[f]['resolution'] for f in all_frames])
     ave_resolution = flex.mean(all_resolutions)
     self.pd['resolution_inspection'] = '%f' % (ave_resolution)
     return self.pd['resolution_inspection']
Example #5
0
 def total_signal(self, fstats, indices):
     #for index in indices:
     #  print index,fstats.master[index].intensity(),flex.sum(fstats.master[index].wts)
     self.addColumn('Integrated',
                    0)  #total integrated signal within the shell
     self.Integrated.format = "%.0f"
     self.addColumn('MeanI', 0)  #mean integrated signal within the shell
     self.MeanI.format = "%.0f"
     self.addColumn('MeanBkg',
                    0)  #mean integrated background within the shell
     self.MeanBkg.format = "%.1f"
     self.addColumn('MeanSz',
                    0)  #mean pixel count for spots within the shell
     self.MeanSz.format = "%.0f"
     self.addColumn('MnEccen', 0)  #mean eccentricity spots within the shell
     self.MnEccen.format = "%.3f"
     self.addColumn('MnSkew', 0)  #mean eccentricity spots within the shell
     self.MnSkew.format = "%.3f"
     index = 0
     for row in xrange(self.S_table_rows):
         row_values = flex.double()
         bkg_values = flex.double()
         sz_values = flex.double()
         eccen_values = flex.double()
         skew_values = flex.double()
         for idx in xrange(self.Population[row]):
             spot_signal = flex.sum(fstats.master[indices[index]].wts)
             bkg_signal = flex.sum(fstats.master[indices[index]].bkg)
             spot_sz = len(fstats.master[indices[index]].wts)
             spot_eccen = fstats.master[indices[index]].model_eccentricity()
             spot_skew = fstats.master[indices[index]].skewness()
             self.Integrated[row] += spot_signal
             row_values.append(spot_signal)
             bkg_values.append(bkg_signal)
             sz_values.append(spot_sz)
             eccen_values.append(spot_eccen)
             skew_values.append(spot_skew)
             index += 1
         if len(row_values) > 0:
             self.MeanI[row] = flex.mean(row_values)
             self.MeanBkg[row] = flex.mean(bkg_values)
             self.MeanSz[row] = flex.mean(sz_values)
             self.MnEccen[row] = flex.mean(eccen_values)
             self.MnSkew[row] = flex.mean(skew_values)
     self.persist_fstats = fstats
     self.persist_indices = indices
Example #6
0
 def total_signal(self,fstats,indices):
   #for index in indices:
   #  print index,fstats.master[index].intensity(),flex.sum(fstats.master[index].wts)
   self.addColumn('Integrated',0) #total integrated signal within the shell
   self.Integrated.format = "%.0f"
   self.addColumn('MeanI',0) #mean integrated signal within the shell
   self.MeanI.format = "%.0f"
   self.addColumn('MeanBkg',0) #mean integrated background within the shell
   self.MeanBkg.format = "%.1f"
   self.addColumn('MeanSz',0) #mean pixel count for spots within the shell
   self.MeanSz.format = "%.0f"
   self.addColumn('MnEccen',0) #mean eccentricity spots within the shell
   self.MnEccen.format = "%.3f"
   self.addColumn('MnSkew',0) #mean eccentricity spots within the shell
   self.MnSkew.format = "%.3f"
   index=0
   for row in xrange(self.S_table_rows):
     row_values = flex.double()
     bkg_values = flex.double()
     sz_values = flex.double()
     eccen_values = flex.double()
     skew_values = flex.double()
     for idx in xrange(self.Population[row]):
       spot_signal = flex.sum(fstats.master[indices[index]].wts)
       bkg_signal = flex.sum(fstats.master[indices[index]].bkg)
       spot_sz = len(fstats.master[indices[index]].wts)
       spot_eccen = fstats.master[indices[index]].model_eccentricity()
       spot_skew = fstats.master[indices[index]].skewness()
       self.Integrated[row]+=spot_signal
       row_values.append(spot_signal)
       bkg_values.append(bkg_signal)
       sz_values.append(spot_sz)
       eccen_values.append(spot_eccen)
       skew_values.append(spot_skew)
       index+=1
     if len(row_values)>0:
       self.MeanI[row]=flex.mean(row_values)
       self.MeanBkg[row]=flex.mean(bkg_values)
       self.MeanSz[row]=flex.mean(sz_values)
       self.MnEccen[row]=flex.mean(eccen_values)
       self.MnSkew[row]=flex.mean(skew_values)
   self.persist_fstats = fstats
   self.persist_indices = indices
Example #7
0
  def sigma_analysis(self):
    #assumes that self.total_signal() and self.background() have already been called.
    self.addColumn('MeanIsigI',0) #mean I over sig(I) for spots within the shell
    self.MeanIsigI.format = "%.3f"
    index=0
    for row in xrange(self.S_table_rows):
      if self.PxlBkgrd[row] == None: continue
      IsigI_values = flex.double()
      for idx in xrange(self.Population[row]):
        # Use International Tables Vol F (2001) equation 11.2.5.9 (p. 214)
        I_s = flex.sum(self.persist_fstats.master[self.persist_indices[index]].wts)
        I_bg = flex.sum(self.persist_fstats.master[self.persist_indices[index]].bkg)
        m_sz = len(self.persist_fstats.master[self.persist_indices[index]].wts)
        n_sz = self.MnWndwSz[row]
        gain = 1.00

        spot_variance = gain * (I_s + I_bg + (m_sz*m_sz) * (1./n_sz) * self.PxlBkgrd[row])

        IsigI_values.append( I_s / math.sqrt(spot_variance))

        index+=1
      if len(IsigI_values)>0: self.MeanIsigI[row]=flex.mean(IsigI_values)
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")
 def get_resolution_inspection(self):
   all_frames = self.images.keys()
   all_resolutions=flex.double([self.images[f]['resolution'] for f in all_frames])
   ave_resolution=flex.mean(all_resolutions)
   self.pd['resolution_inspection']='%f'%(ave_resolution)
   return self.pd['resolution_inspection']
Example #10
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")