Skip to content

Add Integrate2dResult.to_1dresults method - #2986

Merged
kif merged 4 commits into
silx-kit:mainfrom
t20100:Integrate2dResults.to_1dresults
Nov 3, 2026
Merged

kif merged 4 commits into
silx-kit:mainfrom
t20100:Integrate2dResults.to_1dresults

Conversation

@t20100

@t20100 t20100 commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Add a helper method that converts an Integrate2dResult into N Integrate1dResult, one for each azimuth bin.

closes #2985

AI used: Claude used to write tests, review and final rework.

@t20100
t20100 requested a review from kif November 3, 2026 11:11
Comment thread src/pyFAI/containers.py
inside = numpy.where(numpy.logical_and(centers >= min(requested),
centers <= max(requested)))[0]
if requested_range is None:
return slice(None), axis_range

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes rebin1d behavior: before the ranges in the 1D result were set to None if no range was requested. Now it uses the range from the input 2D result.

Comment thread src/pyFAI/containers.py
Comment on lines +139 to +142
if axis_range:
edges = numpy.linspace(*axis_range, len(bin_centers) + 1)
else: # assume close to regular binning
edges = _to_edges(bin_centers)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left it as it was, thought this an be improved: it builds the edges to only pick 2.
Since edges will be stored in the results (#2984) this will no longer be an issue.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely a TODO

Comment thread src/pyFAI/containers.py
self.radial, self._radial_range, radial_range, "radial"
)

_check_regular_binning(self.azimuthal, "azimuth")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept a warning for irregular bins since it may affect the stored azimuth_range.
Likely to be lifted once bin edges are stored in the results (#2984)

Comment thread src/pyFAI/containers.py
numpy.logical_and(
bin_centers >= min(requested_range), bin_centers <= max(requested_range)
)
)[0]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I definitely hate the way this is formatted ... 5 lines instead of 2 and in addition, the symmetry of the upper and lower bound is broken, making the code less readable.

@kif
kif self-requested a review November 3, 2026 15:01

@kif kif left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beside the ugly formatting, LGTM

@kif
kif merged commit 89a4dbe into silx-kit:main Nov 3, 2026
8 checks passed
@t20100
t20100 deleted the Integrate2dResults.to_1dresults branch November 3, 2026 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a way to convert an Intergrate2dResult into N Integrate1dResult

2 participants