silx-kit / pyFAI

Fast Azimuthal Integration in Python
Other
105 stars 95 forks source link

Multigeometry with qip and qoop units does not work #2264

Closed mjdiff closed 1 month ago

mjdiff commented 1 month ago

path_to_mask='/data/visitor/ma6342/id10/20240903/PROCESSED_DATA/mask_001.edf'
path_to_poni='/data/visitor/ma6342/id10/20240903/PROCESSED_DATA/calib_001.poni'

from pyFAI import load
import fabio
from pyFAI.units import get_unit_fiber
from pyFAI.multi_geometry import MultiGeometry
unit_qip = get_unit_fiber(name="qip_nm^-1", sample_orientation=3)
unit_qoop = get_unit_fiber(name="qoop_nm^-1", sample_orientation=3)
data  =fabio.open(path_to_mask).data
ai = load(path_to_poni)
data_path = '/data/visitor/ma6342/id10/20240903/RAW_DATA/LaB6/LaB6_0001/scan0004/eiger4m_0000.h5'
data=fabio.open(data_path).data

mg = MultiGeometry(ais=[ai], radial_range=[0,-30],unit=(unit_qip,unit_qoop))

res2d = mg.integrate2d(lst_data=[data], npt_rad=1000, method=('no', 'csr', 'cython'))

#res2d_ai = ai.integrate2d(data=data, npt_rad=1000, unit=(unit_qoop, unit_qip), method=('no','csr','cython')) #this works
ERROR:pyFAI.units:Unable to recognize this type unit '(qip_nm^-1, qoop_nm^-1)' of type <class 'tuple'>. Valid units are r_mm, r_m, 2th_deg, 2th_rad, q_nm^-1, q_A^-1, d_m, d_nm, d_A, d*2_A^-2, d*2_nm^-2, log10(q.m)_None, log(q.nm)_None, log(1+q.nm)_None, log(1+q.A)_None, arcsinh(q.nm)_None, arcsinh(q.A)_None, qx_nm^-1, qy_nm^-1, exitangle_rad, qxgi_nm^-1, qygi_nm^-1, qzgi_nm^-1, qip_nm^-1, qoop_nm^-1, qtot_nm^-1, qxgi_A^-1, qygi_A^-1, qzgi_A^-1, qip_A^-1, qoop_A^-1, qtot_A^-1, chi_rad, chi_deg
ERROR:pyFAI.units:Unable to recognize this type unit 'None' of type <class 'NoneType'>. Valid units are r_mm, r_m, 2th_deg, 2th_rad, q_nm^-1, q_A^-1, d_m, d_nm, d_A, d*2_A^-2, d*2_nm^-2, log10(q.m)_None, log(q.nm)_None, log(1+q.nm)_None, log(1+q.A)_None, arcsinh(q.nm)_None, arcsinh(q.A)_None, qx_nm^-1, qy_nm^-1, exitangle_rad, qxgi_nm^-1, qygi_nm^-1, qzgi_nm^-1, qip_nm^-1, qoop_nm^-1, qtot_nm^-1, qxgi_A^-1, qygi_A^-1, qzgi_A^-1, qip_A^-1, qoop_A^-1, qtot_A^-1
EdgarGF93 commented 1 month ago

We can fix the whole compatibility between GrazingIncidence and MultiGeometry in a single PR. MultiGeometry does not accept a tuple as unit parameter, and its own integrate2d method does not accept unit at all, so for the moment, we are fixing manually the unit, and also the radial and azimuthal range, like this:

qip = get_unit_fiber(name='qip_nm^-1', sample_orientation=3)
qoop = get_unit_fiber(name='qoop_nm^-1', sample_orientation=3)
mg = MultiGeometry(ais=[ai])
mg.unit = (qip, qoop)
mg.radial_range = None
mg.azimuth_range = None
res2d_mg = mg.integrate2d(lst_data=[data], npt_rad=1000, npt_azim=1000, method=('no', 'csr', 'cython'))
mg = MultiGeometry(ais=[ai])
EdgarGF93 commented 1 month ago

But this approach is not correct, because the unit of the result of this integration is:

res2d_mg.unit

((qip_nm^-1, qoop_nm^-1), chi_deg)

So for example, jupyter.plot2d is going to crash when it's about the set the labels in the plot:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[29], line 1
----> 1 plot2d(res2d_mg)
      2 pass

File /cvmfs/hpc.esrf.fr/software/packages/ubuntu20.04/x86_64/scattering/2024.08.30/lib/python3.11/site-packages/pyFAI/gui/jupyter/_plot.py:164, in plot2d(result, calibrant, label, ax)
    162     ax.set_title(label)
    163 if isinstance(result.unit, (list, tuple)) and len(result.unit) == 2:
--> 164     ax.set_xlabel(result.unit[0].label)
    165     ax.set_ylabel(result.unit[1].label)
    166 else:

AttributeError: 'tuple' object has no attribute 'label'
EdgarGF93 commented 1 month ago

2266

EdgarGF93 commented 1 month ago

finished