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])
 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])
Exemple #3
0
 def calculate_saturation(self,fstats,image):
   S = SaturationMeasure()
   resolution_spots = fstats[fstats.most_recent_child()]
   S.n_resolution_spots = len(resolution_spots)
   S.n_goodspots = fstats['N_goodspots']
   ispots = flex.int()
   for i in xrange(S.n_resolution_spots):
     spt = resolution_spots[i]
     ispots.append( image.linearintdata[(spt.max_pxl_x(),spt.max_pxl_y())] )
   S.OverCount = (ispots >= int(image.saturation)).count(True)
   perm = flex.sort_permutation(ispots,True)
   spot_peaks = flex.int([ispots[p] for p in perm[0:min(50,len(perm))]])
   S.n_sample = len(spot_peaks)
   if S.n_sample < 2: #no peaks on the image
     S.p_saturation = 0.0; return S
   S.average = float(reduce(lambda x,y:x+y, spot_peaks))/len(spot_peaks)
   S.p_saturation = S.average/image.saturation
   # for Raxis-II and Mar Image Plates, it has been noticed that image.linearintdata
   # can contain pixel values greater than image.saturation.  No doubt this is
   # a shortcoming in how the pixel values are decoded for overloaded values (not fixed)
   return S
Exemple #4
0
  def determine_maxcell(self,frame,pd):
    if self.phil_params.codecamp.maxcell != None:
      self.images[frame]['maxcel']=self.phil_params.codecamp.maxcell
      return
    if self.images[frame]['N_spots_inlier']>2:
      neighbors   = self.images[frame]['neighbors']
      n_ave,n_std = scitbx_stats(neighbors)

      average_nearest_neighbor = n_ave

      NNBIN = self.NspotMin//2 # recommended bin size for nearest neighbor histogram
      peak_of_interest = n_ave

      for pss in xrange(1):  #make two passes thru histo

        fineness = max( [self.pixel_size / 2.,
          peak_of_interest / (1.0+float(len(neighbors))/float(NNBIN))] )
        min_neighbors = min(neighbors)

        def histo_index_to_mm(index):
          return min_neighbors+index*fineness

        #neighbor_histogram
        histogram = [0]*int(peak_of_interest*4/fineness)
        for y in neighbors:
          ibin = int( (y-min_neighbors)/fineness )
          if ibin < len(histogram):
            histogram[ibin]+=1

        if TALLY2:
          for row in xrange(len(histogram)):
            low = histo_index_to_mm(row)
            hi  = histo_index_to_mm(row+1)
            print "%.2f to %.2f, %5.1f Ang"%(low,hi,radius_to_resol(histo_index_to_mm(row+.5),pd)),
            print "*"*histogram[row],
            print

        most_probable_neighbor = histo_index_to_mm(0.5 + histogram.index(max(histogram)))

        #Compute yet another measure of unit cell--first peak in histogram
        peak1 = 0; peak1i = 0
        for peakpt in xrange(len(histogram)):
          if histogram[peakpt]>peak1i:
            peak1=peakpt; peak1i=histogram[peakpt]
          if histogram[peakpt]<0.5*peak1i and peak1i> 0.1*(max(histogram)):
            break

        first_peak_if_any = histo_index_to_mm(0.5 + peak1)
        peak_of_interest = min(first_peak_if_any,most_probable_neighbor)

        # Another trial measure: 5th percentile neighbor
        sort_perm = flex.sort_permutation(neighbors)
        cutoff_mm = neighbors[sort_perm[ int(0.05*len(sort_perm)) ]]

      #Caveat: this rough calculation becomes less accurate for non-zero two-theta
      self.images[frame]['neighboring_spot_separation']=min(most_probable_neighbor , cutoff_mm)
      MAXTOL = 1.5 # Margin of error for max unit cell estimate
                   # 11/19/02 old value 1.4; new value 2.0 to accomodate a
                   #   pathological case where zone is down the large unit cell.
                   #   Larger value is now tolerable because of post-mosflm
                   #   check for systematic absences.
                   # 9/28/03 change back to 1.5 with new autoindexer because
                   #   value of 2.0 can (infrequently) lead to misindexing;
                   #   based on experience preparing figure 4.
      maxcell = max(MAXTOL * radius_to_resol(most_probable_neighbor,pd),
                    0.0    * radius_to_resol(min(neighbors),pd),
                    0.0    * radius_to_resol(first_peak_if_any,pd),
                    MAXTOL * radius_to_resol(cutoff_mm,pd))
      self.images[frame]['maxcel']=maxcell