def test_cythonSP_vs_fit2d(self): """ Compare cython splitPixel with results of fit2d """ logger.info(self.ai.__repr__()) pos = self.ai.cornerArray(self.data.shape) t0 = time.time() logger.info("in test_cythonSP_vs_fit2d Before SP") tth, I = self.ai.xrpd_splitPixel(self.data, len(self.fit2d), self.tmpfiles["cythonSP"], correctSolidAngle=False) logger.info("in test_cythonSP_vs_fit2d Before") t1 = time.time() - t0 # logger.info(tth) # logger.info(I) rwp = Rwp((tth, I), self.fit2d.T) logger.info("Rwp cythonSP(t=%.3fs)/fit2d = %.3f" % (t1, rwp)) if logger.getEffectiveLevel() == logging.DEBUG: logger.info("Plotting results") fig = pylab.figure() fig.suptitle('CythonSP Histogram vs Fit2D: Rwp=%.3f' % rwp) sp = fig.add_subplot(111) sp.plot(self.fit2d.T[0], self.fit2d.T[1], "-b", label='fit2d') sp.plot(tth, I, "-r", label="cython") handles, labels = sp.get_legend_handles_labels() fig.legend(handles, labels) fig.show() input("Press enter to quit") assert rwp < 11
def test_cython_vs_numpy(self): """ Compare cython histogram with numpy histogram """ # logger.info(self.ai.__repr__()) data = self.data tth_np, I_np = self.ai.xrpd_numpy(data, len(self.fit2d), correctSolidAngle=False) tth_cy, I_cy = self.ai.xrpd_cython(data, len(self.fit2d), correctSolidAngle=False) logger.info("before xrpd_splitPixel") tth_sp, I_sp = self.ai.xrpd_splitPixel(data, len(self.fit2d), correctSolidAngle=False) logger.info("After xrpd_splitPixel") rwp = Rwp((tth_cy, I_cy), (tth_np, I_np)) logger.info("Rwp = %.3f" % rwp) if logger.getEffectiveLevel() == logging.DEBUG: logging.info("Plotting results") fig = pylab.figure() fig.suptitle('Numpy Histogram vs Cython: Rwp=%.3f' % rwp) sp = fig.add_subplot(111) sp.plot(self.fit2d.T[0], self.fit2d.T[1], "-y", label='fit2d') sp.plot(tth_np, I_np, "-b", label='numpy') sp.plot(tth_cy, I_cy , "-r", label="cython") sp.plot(tth_sp, I_sp , "-g", label="SplitPixel") handles, labels = sp.get_legend_handles_labels() fig.legend(handles, labels) fig.show() input("Press enter to quit") assert rwp < 3
def test_cython_vs_numpy(self): """ Compare cython histogram with numpy histogram """ # logger.info(self.ai.__repr__()) data = self.data tth_np, I_np = self.ai.xrpd_numpy(data, len(self.fit2d), correctSolidAngle=False) tth_cy, I_cy = self.ai.xrpd_cython(data, len(self.fit2d), correctSolidAngle=False) logger.info("before xrpd_splitPixel") tth_sp, I_sp = self.ai.xrpd_splitPixel(data, len(self.fit2d), correctSolidAngle=False) logger.info("After xrpd_splitPixel") rwp = Rwp((tth_cy, I_cy), (tth_np, I_np)) logger.info("Rwp = %.3f" % rwp) if logger.getEffectiveLevel() == logging.DEBUG: logging.info("Plotting results") fig = pylab.figure() fig.suptitle('Numpy Histogram vs Cython: Rwp=%.3f' % rwp) sp = fig.add_subplot(111) sp.plot(self.fit2d.T[0], self.fit2d.T[1], "-y", label='fit2d') sp.plot(tth_np, I_np, "-b", label='numpy') sp.plot(tth_cy, I_cy, "-r", label="cython") sp.plot(tth_sp, I_sp, "-g", label="SplitPixel") handles, labels = sp.get_legend_handles_labels() fig.legend(handles, labels) fig.show() input("Press enter to quit") assert rwp < 3
def test_cython_vs_fit2d(self): """ Compare cython histogram with results of fit2d """ # logger.info(self.ai.__repr__()) tth, I = self.ai.xrpd_cython(self.data, len(self.fit2d), self.tmpfiles["cython"], correctSolidAngle=False, pixelSize=None) # logger.info(tth) # logger.info(I) rwp = Rwp((tth, I), self.fit2d.T) logger.info("Rwp cython/fit2d = %.3f" % rwp) if logger.getEffectiveLevel() == logging.DEBUG: logger.info("Plotting results") fig = pylab.figure() fig.suptitle('Cython Histogram vs Fit2D: Rwp=%.3f' % rwp) sp = fig.add_subplot(111) sp.plot(self.fit2d.T[0], self.fit2d.T[1], "-b", label='fit2d') sp.plot(tth, I, "-r", label="cython") handles, labels = sp.get_legend_handles_labels() fig.legend(handles, labels) fig.show() input("Press enter to quit") assert rwp < 11
def diff_img(ref, obt, comment=""): """ Highlight the difference in images """ assert ref.shape == obt.shape delta = abs(obt - ref) if delta.max() > 0: from pyFAI.gui_utils import pyplot as plt fig = plt.figure() ax1 = fig.add_subplot(2, 2, 1) ax2 = fig.add_subplot(2, 2, 2) ax3 = fig.add_subplot(2, 2, 3) im_ref = ax1.imshow(ref) plt.colorbar(im_ref) ax1.set_title("%s ref" % comment) im_obt = ax2.imshow(obt) plt.colorbar(im_obt) ax2.set_title("%s obt" % comment) im_delta = ax3.imshow(delta) plt.colorbar(im_delta) ax3.set_title("delta") imax = delta.argmax() x = imax % ref.shape[-1] y = imax // ref.shape[-1] ax3.plot([x], [y], "o", scalex=False, scaley=False) fig.show() from pyFAI.utils import input input()
def test_splitBBox(self): data = numpy.ones((2000, 2000), dtype="float64") ai = AzimuthalIntegrator(0.1, 1e-2, 1e-2, pixel1=1e-5, pixel2=1e-5) I = ai.xrpd2_splitBBox(data, 2048, 2048, correctSolidAngle=False, dummy=-1.0)[0] # I = ai.xrpd2(data, 2048, 2048, correctSolidAngle=False, dummy= -1.0) if logger.getEffectiveLevel() == logging.DEBUG: logging.info("Plotting results") fig = pylab.figure() fig.suptitle('cacking of a flat image: SplitBBox') sp = fig.add_subplot(111) sp.imshow(I, interpolation="nearest") fig.show() input("Press enter to quit") I[I == -1.0] = 1.0 assert abs(I.min() - 1.0) < self.epsilon assert abs(I.max() - 1.0) < self.epsilon
def diff_crv(ref, obt, comment=""): """ Highlight the difference in vectors """ assert ref.shape == obt.shape delta = abs(obt - ref) if delta.max() > 0: from pyFAI.gui_utils import pyplot as plt fig = plt.figure() ax1 = fig.add_subplot(1, 2, 1) ax2 = fig.add_subplot(1, 2, 2) im_ref = ax1.plot(ref, label="%s ref" % comment) im_obt = ax1.plot(obt, label="%s obt" % comment) im_delta = ax2.plot(delta, label="delta") fig.show() from pyFAI.utils import input input()
def test_numpy_vs_fit2d(self): """ Compare numpy histogram with results of fit2d """ # logger.info(self.ai.__repr__()) tth, I = self.ai.xrpd_numpy(self.data, len(self.fit2d), self.tmpfiles["numpy"], correctSolidAngle=False) rwp = Rwp((tth, I), self.fit2d.T) logger.info("Rwp numpy/fit2d = %.3f" % rwp) if logger.getEffectiveLevel() == logging.DEBUG: logger.info("Plotting results") fig = pylab.figure() fig.suptitle('Numpy Histogram vs Fit2D: Rwp=%.3f' % rwp) sp = fig.add_subplot(111) sp.plot(self.fit2d.T[0], self.fit2d.T[1], "-b", label='fit2d') sp.plot(tth, I, "-r", label="numpy histogram") handles, labels = sp.get_legend_handles_labels() fig.legend(handles, labels) fig.show() input("Press enter to quit") assert rwp < 11