def test_integrate(self): d=Data(path.join(self.datadir,"SLD_200919.dat")) d.setas="x..y" d.integrate(result=True,header="Total_M") result=d["Total_M"] self.assertAlmostEqual(result,4.19687459365,7,"Integrate returned the wrong result!") d.setas[-1]="y" d.plot(multiple="y2") self.assertEqual(len(d.axes),2,"Failed to produce plot with double y-axis") d.close("all") d.setas="x..y" fx=d.interpolate(None) self.assertEqual(fx(np.linspace(1,1500,101)).shape,(101,7),"Failed to get the interpolated shape right")
d=Data(filename,setas="xy") #Load the low angle scan #Now get the section of the data file that has the peak positions # This is really doing the hard work # We differentiate the data using a Savitsky-Golay filter with a 5 point window fitting quartics. # This has proved most succesful for me looking at some MdV data. # We then threshold for zero crossing of the derivative # And check the second derivative to see whether we like the peak as signficant. This is the significance parameter # and seems to be largely empirical # Finally we interpolate back to the complete data set to make sure we get the angle as well as the counts. d.lmfit(ExponentialModel,result=True,replace=False,header="Envelope") d.subtract("Counts","Envelope",replace=False,header="peaks") d.setas="xy" sys.exit() t=Data(d.interpolate(d.peaks(significance=sensitivity,width=8,poly=4))) t.column_headers=copy(d.column_headers) d%='peaks' t%='peaks' d.setas="xy" d.labels[d.find_col('Angle')]=r"Reflection Angle $\theta$" t.del_rows(0, lambda x,y: x<critical_edge) t.setas="xy" t.template.fig_width=7.0 t.template.fig_height=5.0 t.plot(fmt='go', plotter=pyplot.semilogy) main_fig=d.plot(figure=t.fig, plotter=pyplot.semilogy) d.show() #Now convert the angle to sin^2 t.apply(lambda x: np.sin(np.radians(x[0]/2.0))**2, 0,header=r"$sin^2\theta$")
d = Data(filename, setas="xy") # Load the low angle scan # Now get the section of the data file that has the peak positions # This is really doing the hard work # We differentiate the data using a Savitsky-Golay filter with a 5 point window fitting quartics. # This has proved most succesful for me looking at some MdV data. # We then threshold for zero crossing of the derivative # And check the second derivative to see whether we like the peak as signficant. This is the significance parameter # and seems to be largely empirical # Finally we interpolate back to the complete data set to make sure we get the angle as well as the counts. d.lmfit(ExponentialModel, result=True, replace=False, header="Envelope") d.subtract("Counts", "Envelope", replace=False, header="peaks") d.setas = "xy" sys.exit() t = Data(d.interpolate(d.peaks(significance=sensitivity, width=8, poly=4))) t.column_headers = copy(d.column_headers) d %= "peaks" t %= "peaks" d.setas = "xy" d.labels[d.find_col("Angle")] = r"Reflection Angle $\theta$" t.del_rows(0, lambda x, y: x < critical_edge) t.setas = "xy" t.template.fig_width = 7.0 t.template.fig_height = 5.0 t.plot(fmt="go", plotter=pyplot.semilogy) main_fig = d.plot(figure=t.fig, plotter=pyplot.semilogy) d.show() # Now convert the angle to sin^2 t.apply(lambda x: np.sin(np.radians(x[0] / 2.0)) ** 2, 0, header=r"$sin^2\theta$")