def test_calibrate_no_search(self): #from uncertainties import unumpy x,y = self.edxdata['LaB6'] searcher = WaveletPeakSearcher(1.2,25,1.15,critical_sep=2,noiselevel=20,min_ridge_length=9, min_child_length=8,ridge_skip=0) searcher.set_data(x,y) pks = searcher.identify_peaks() cf = ChunkFitter(x,pks,shape='g') cf.refine(y) candidates = np.array([peak.centre for peak in cf.peaks]) #uncertainty = unumpy.std_devs(candidates) #uncertainty[uncertainty==0] = 1 #candidates = unumpy.nominal_values(candidates) unit_cell = [4.15695,4.15695,4.15695,90,90,90] space_group = 'pm-3m' c = match_fit(candidates,unit_cell,space_group) self.assertLess(abs(c.values[0]),1e-9) self.assertAlmostEqual(c.values[1], 0.001942,5) self.assertLess(abs(c.values[2]),0.005)
def test_calibration_fakedata(self): c0,c1 = 2,0.0019 b = unitcell.get_unique_peaks([4.04,4.04,4.04,90,90,90],'fm-3m',0,6)[0] a = -c0 + b*(1/c1) a = np.hstack((a[0:1],[1500],a[1:2],[1900],a[2:])) cal = match_fit(a,[4.04,4.04,4.04,90,90,90],'fm-3m',qmax=7) cal = cal.values self.assertAlmostEqual(cal[0],0,3) self.assertAlmostEqual(cal[1],c1,4) self.assertAlmostEqual(cal[2],c1*c0,4)
cal = calibration.search_match_fit(x,y,unit_cell,space_group,**settings) #the rest is all plotting sob = cal.search[0] #calibration objects may have data from several spectra f,axs = plt.subplots(2,sharex=True) ax1,ax2 = axs ax1.plot(sob.x,sob.y,'b') ax1.plot(sob.x,sob.pfit,'r') ax1.plot(sob.centres,sob.heights, 'ro',markerfacecolor='none') ax1.set_yscale('log') mob = cal.match[0] #calibration objects may have data from several spectra ax2.plot(mob.candidates.filtered,mob.known.filtered,'ko') ax2.plot(cal.xfit,cal.yfit,'r--') ax2.set_xbound(0,mob.candidates.filtered.max()) #Now test the method without using peak search #i.e. some candidates found by some other method preferred by the user cands = [775.8, 1098.3, 1345.4, 1553.8, 1737.1, 1903.6, 2197.5, 2330.9] cal = calibration.match_fit(cands,unit_cell,space_group) #again - most code is plotting mob = cal.match[0] f,ax = plt.subplots(1) ax.plot(mob.candidates.filtered,mob.known.filtered,'ko') ax.plot(cal.xfit,cal.yfit,'r--') ax.set_xbound(0,mob.candidates.filtered.max()) plt.show() #