#!/usr/bin/env python # coding: utf-8 # # 2D Integration in non-azimuthal space # # In this tutorial, an image is intgrated in `qx/qy` space instead of `2theta/chi`. More fancy spaces are even possible ... # In[1]: get_ipython().run_line_magic('matplotlib', 'inline') # %matplotlib widget # In[2]: import numpy import pyFAI from pyFAI.test.utilstest import UtilsTest import fabio from pyFAI.gui import jupyter from pyFAI import units from pyFAI.method_registry import Method,IntegrationMethod # In[3]: img = fabio.open(UtilsTest.getimage("moke.tif")).data jupyter.display(img) # In[4]: # According to the description in the image, we have: det = pyFAI.detector_factory("Detector", {"pixel1":1e-4,"pixel2":1e-4}) ai = pyFAI.load({"detector": det, "wavelength": 1e-10}) ai.setFit2D(100, 300, 300) ai # In[5]: len(IntegrationMethod.select_method(dim=2)) # In[6]: for m in IntegrationMethod.select_method(dim=2): print(m, end="") if m.algorithm=="histogram" and m.target is not None: print("OpenCL histogram skipped") continue try: res = ai.integrate2d(img, 400,400, method=m, unit=("qx_nm^-1","qy_nm^-1")) except: print("broken") else: print(f"{res[1].min():.2f}={numpy.nanmean(res[0]):.2f} ± {numpy.nanstd(res[0]):.2f}") # In[7]: m = IntegrationMethod.select_method(dim=2, split="full", algo="CSR")[0] print(m) ai.reset() res = ai.integrate2d(img, 400,400, method=m, unit=("qx_nm^-1", "qy_nm^-1")) jupyter.plot2d(res) # In[8]: ai._cached_array.keys() # In[9]: # Now with a new space: 2thx, 2thy: tthx = pyFAI.units.register_radial_unit("tthx_deg", scale=180.0/numpy.pi, label=r"$2\theta$ angle along x ($^{o}$)", formula="arctan2(x,z)", short_name="2thx", unit_symbol="^{o}", positive=False) tthy = pyFAI.units.register_azimuthal_unit("tthy_deg", scale=180.0/numpy.pi, label=r"$2\theta$ angle along y ($^{o}$)", formula="arctan2(y,z)", short_name="2thy", unit_symbol="^{o}", positive=False) res = ai.integrate2d(img, 400,400, method=m, unit=("tthx_deg", "tthy_deg")) jupyter.plot2d(res) pass # In[10]: #Nota: it is also possible to integrate along the radial dim ... but for now, no way to provide limitation in radius. jupyter.plot1d(ai.integrate1d(img, 400, unit="chi_deg", method=("no", "histogram", "cython"))) pass # In[ ]: