def search_for_peaks (self, peaks, thr, max_peak_size, num_of_segments, perc): #thr=self.threshold # 100: raw counts threshold for locating peaks #max_peak_size=self.mindist # 10: max allowed peak size with pixels above local background + Imin #num_of_segments = [self.pbox,self.pbox] # [50.,50.]: number of segments in X and Y for local labckground estimation #perc=self.bbox # 1.0: percent of median for background topX=self.imArraySize[0] topY=self.imArraySize[1] img1=cgd.congrid(self.imArray, [1000,1000]) bg=self.estimate_local_background (img1, 50, 50, 100, 1.0) w=np.where(img1-bg > thr) for i in range(len(w[0])): XYs=[w[1][i],w[0][i]] if img1[XYs[1],XYs[0]]-bg[XYs[1],XYs[0]] > thr : XY=[0.0,0.0] aa=self.grow_peak(img1, bg, XYs[1],XYs[0], thr/2., 1000, 1000) if (max([aa[1]-aa[0], aa[3]-aa[2]]) < max_peak_size) and (aa[6] > thr) : XY[0]=aa[5]*topX/1000 XY[1]=aa[4]*topY/1000 peak=myPeakTable.myPeak() peak.setDetxy(XY) #peak.setIntAD=img1[aa[4],aa[5]] #ref_peak.setgonio=im.sts.gonio peaks.addPeak(peak) img1[aa[2]:aa[3],aa[0]:aa[1]]=0 peaks.find_multiple_peak_copies()
def generate_peaks_laue(self, ub, optable, pred, en, exti, DAC_open): gonio = [0., 0., 0., 0., 0., 0.] for h in range(pred.h1, pred.h2 + 1): for k in range(pred.k1, pred.k2 + 1): for l in range(pred.l1, pred.l2 + 1): if (h == 0 and k == 0 and l == 0): continue hkl = np.asarray([h, k, l]) if (syst_extinction(exti, hkl) == 1): xyz = np.dot(ub, hkl) if (vlength(xyz) > 0.0000001): #print 'hkl is : ', h,k,l Ene = en_from_xyz(xyz) if (Ene > en[0] and Ene <= en[1]): pix = np.asarray( self.calculate_pixels_from_xyz(xyz, gonio)) r = pix - np.asarray([self.beamx, self.beamy]) r = sqrt(r[0]**2 + r[1]**2) psi2 = self.calculate_psi_angles(gonio, pix) if pix[0] > 0 and pix[0] < self.nopixx-1 and \ pix[1]>0 and pix[1] < self.nopixy -1 and abs(psi2[0,1]) < DAC_open : refpeak = myPeakTable.myPeak() refpeak.DetXY = pix refpeak.gonio = gonio refpeak.XYZ = xyz refpeak.energies[0] = Ene refpeak.hkl = hkl optable.addPeak(refpeak)
def generate_all_peaks (self, ub, pktable, wv, pred, exti, dac_open, box): pktable.zero() kt = self.read_kappa_and_ttheta() gonio = np.zeros(6, dtype=np.float32) # 2theta gonio[1] = kt[1] # kappa/chi gonio[4] = pred.chi boxval = self.topLevel.read_box_change() refpeak = myPeakTable.myPeak() refpeak.IntSSD[0:2]=[boxval, boxval] for h in range (pred.h1, pred.h2+1) : for k in range (pred.k1, pred.k2+1) : for l in range (pred.l1, pred.l2+1) : hkl = [h,k,l] extinct = syst_extinction (exti, hkl) if extinct == 1 : xyz = np.dot (hkl,ub) om = get_omega(A_to_kev(wv), xyz) #om = solve_general_axis (A_to_kev(wv), xyz, gonio) om0 = om[0] if om0 >= pred.om_start and om0 <= pred.om_start + pred.om_range : gonio[3] = om0 pix = self.calculate_pixels_from_xyz(xyz, gonio) r = [pix[0]-self.beamx, pix[1]-self.beamy] r = math.sqrt (r[0]**2+r[1]**2) psi2 = self.calculate_psi_angles(gonio, pix) print pix[0], psi2[0][1] if (pix[0]>0 and pix[0] < self.nopixx-1 and abs(psi2[0,1]< dac_open)) : refpeak.setDetxy (pix) refpeak.gonio = gonio refpeak.xyz = xyz refpeak.hkl = hkl refpeak.IntSSD[0:2] = [box[0], box[0]] pktable.appendPeak (refpeak)
def search_for_peaks(self, peaks, thr, max_peak_size, num_of_segments, perc): #thr=self.threshold # 100: raw counts threshold for locating peaks #max_peak_size=self.mindist # 10: max allowed peak size with pixels above local background + Imin #num_of_segments = [self.pbox,self.pbox] # [50.,50.]: number of segments in X and Y for local labckground estimation #perc=self.bbox # 1.0: percent of median for background #need to add intssd, gonio and any other parameters for the peak. topX = self.imArraySize[0] topY = self.imArraySize[1] img1 = cgd.congrid(self.imArray, [1000, 1000]) bg = self.estimate_local_background(img1, self.locBcgr, self.locBcgr, 100, 1.0) w = np.where(img1 - bg > thr) for i in range(len(w[0])): XYs = [w[1][i], w[0][i]] if img1[XYs[1], XYs[0]] - bg[XYs[1], XYs[0]] > thr: XY = [0.0, 0.0] aa = self.grow_peak(img1, bg, XYs[1], XYs[0], thr / 2., 1000, 1000) if (max([aa[1] - aa[0], aa[3] - aa[2]]) < max_peak_size) and (aa[6] > thr): XY[0] = aa[5] * topX / 1000 XY[1] = aa[4] * topY / 1000 peak = myPeakTable.myPeak() peak.setDetxy(XY) #peak.setIntAD=img1[aa[4],aa[5]] #ref_peak.setgonio=im.sts.gonio peaks.addPeak(peak) img1[aa[2]:aa[3], aa[0]:aa[1]] = 0 peaks.find_multiple_peak_copies()
def search_for_peaks_arr(self, arr, peaks, thr, max_peak_size, num_of_segments, perc): sxy = arr.shape topX = sxy[1] topY = sxy[0] img1 = cgd.congrid(arr, [1000, 1000]) bg = self.estimate_local_background(img1, self.locBcgr, self.locBcgr, 100, 1.0) w = np.where(img1 - bg > thr) for i in range(len(w[0])): XYs = [w[1][i], w[0][i]] if img1[XYs[1], XYs[0]] - bg[XYs[1], XYs[0]] > thr: XY = [0.0, 0.0] aa = self.grow_peak(img1, bg, XYs[1], XYs[0], thr / 2., 1000, 1000) if (max([aa[1] - aa[0], aa[3] - aa[2]]) < max_peak_size) and (aa[6] > thr): XY[0] = aa[5] * topX / 1000 XY[1] = aa[4] * topY / 1000 peak = myPeakTable.myPeak() peak.setDetxy(XY) #peak.setIntAD=img1[aa[4],aa[5]] #ref_peak.setgonio=im.sts.gonio peaks.addPeak(peak) img1[aa[2]:aa[3], aa[0]:aa[1]] = 0 peaks.find_multiple_peak_copies()
def generate_peaks_laue (self, ub, optable, pred, en, exti, DAC_open): gonio = [0.,0.,0.,0.,0.,0.] for h in range(pred.h1,pred.h2+1) : for k in range (pred.k1, pred.k2+1) : for l in range (pred.l1, pred.l2+1) : if (h==0 and k==0 and l==0) : continue hkl =np.asarray([h, k, l]) if (syst_extinction (exti, hkl)==1) : xyz = np.dot (ub, hkl) if (vlength(xyz) >0.0000001) : #print 'hkl is : ', h,k,l Ene = en_from_xyz(xyz) if (Ene > en[0] and Ene <= en[1]) : pix = np.asarray(self.calculate_pixels_from_xyz (xyz, gonio)) r = pix - np.asarray([self.beamx, self.beamy]) r = sqrt(r[0]**2+r[1]**2) psi2 = self.calculate_psi_angles (gonio, pix) if pix[0] > 0 and pix[0] < self.nopixx-1 and \ pix[1]>0 and pix[1] < self.nopixy -1 and abs(psi2[0,1]) < DAC_open : refpeak = myPeakTable.myPeak() refpeak.DetXY = pix refpeak.gonio = gonio refpeak.XYZ = xyz refpeak.energies[0] =Ene refpeak.hkl = hkl optable.addPeak (refpeak)
def search_for_peaks_arr (self, arr, peaks, thr, max_peak_size, num_of_segments, perc): sxy = arr.shape topX=sxy[1] topY=sxy[0] img1=cgd.congrid(arr, [1000,1000]) bg=self.estimate_local_background (img1, 50, 50, 100, 1.0) w=np.where(img1-bg > thr) for i in range(len(w[0])): XYs=[w[1][i],w[0][i]] if img1[XYs[1],XYs[0]]-bg[XYs[1],XYs[0]] > thr : XY=[0.0,0.0] aa=self.grow_peak(img1, bg, XYs[1],XYs[0], thr/2., 1000, 1000) if (max([aa[1]-aa[0], aa[3]-aa[2]]) < max_peak_size) and (aa[6] > thr) : XY[0]=aa[5]*topX/1000 XY[1]=aa[4]*topY/1000 peak=myPeakTable.myPeak() peak.setDetxy(XY) #peak.setIntAD=img1[aa[4],aa[5]] #ref_peak.setgonio=im.sts.gonio peaks.addPeak(peak) img1[aa[2]:aa[3],aa[0]:aa[1]]=0 peaks.find_multiple_peak_copies()