silx-kit / pyFAI

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

Unit scaling in `center_array` is only applied to the first column/row #1996

Closed loichuder closed 11 months ago

loichuder commented 11 months ago

Relevant code:

https://github.com/silx-kit/pyFAI/blob/327676400247078e19268426f94fba978004a2bd/src/pyFAI/geometry/core.py#L876

Short version

Since center_array expects to work with a 3D array but I get a 2D array, the unit scaling applied to the last dimension of the resulting center_array is only applied to the first column/row.

https://github.com/silx-kit/pyFAI/blob/327676400247078e19268426f94fba978004a2bd/src/pyFAI/geometry/core.py#L919

Long version

Reading center_array docstring, the returned array is expected to be 3D.

https://github.com/silx-kit/pyFAI/blob/327676400247078e19268426f94fba978004a2bd/src/pyFAI/geometry/core.py#L886

However, reading the code, the returned ary comes from the unit.equation which returns an array with the same dimensionality as x, y, z. And x, y, z are 2D arrays (if shape is a tuple of 2 integers as indicated by the docstring) since pos is 3D. So ary is in fact 2D...

To add more confusion, the main part of the docstring indicates that the returned array is 2D.

https://github.com/silx-kit/pyFAI/blob/327676400247078e19268426f94fba978004a2bd/src/pyFAI/geometry/core.py#L878

But perhaps am I missing something in my analysis and/or call of center_array ?

kif commented 11 months ago

Hi Loic,

Thanks for highlighting those unconsistencies in the docstring. There are obviouly copy-paste error but maybe more than that ...

The result cannot be 4D (y,x,corner,position) and I except it to be 2D. If the array is 3D, the radial is the index 0 in the last dim thus the scaling (index1 would be the azimuthal angle) thus the scaling. Nota, the scaling would be wrongly applies if ndim=2 and this is a bug. Scaling is True only outside pyFAI, internally, the scale is always applied last (pyFAI works in SI unit all the time and converts the result)