From e77e31d11588b1149e85ae42de1598c831da1d2f Mon Sep 17 00:00:00 2001 From: Edgar Gutierrez Fernandez Date: Thu, 14 Nov 2024 17:03:33 +0100 Subject: [PATCH 1/3] simplify fiber integrator --- src/pyFAI/integrator/fiber.py | 173 +++++----------------------------- 1 file changed, 25 insertions(+), 148 deletions(-) diff --git a/src/pyFAI/integrator/fiber.py b/src/pyFAI/integrator/fiber.py index d92eb022e..ac9442ba8 100644 --- a/src/pyFAI/integrator/fiber.py +++ b/src/pyFAI/integrator/fiber.py @@ -30,7 +30,7 @@ __contact__ = "edgar.gutierrez-fernandez@esr.fr" __license__ = "MIT" __copyright__ = "European Synchrotron Radiation Facility, Grenoble, France" -__date__ = "13/11/2024" +__date__ = "14/11/2024" __status__ = "stable" __docformat__ = 'restructuredtext' @@ -155,6 +155,8 @@ def integrate_fiber(self, data, :param pyFAI.units.UnitFiber/str unit_ip: unit to describe the in-plane axis. If not provided, it takes qip_nm^-1 :param list ip_range: The lower and upper range of the in-plane unit. If not provided, range is simply (data.min(), data.max()). Values outside the range are ignored. Optional. :param bool vertical_integration: If True, integrates along unit_ip; if False, integrates along unit_oop + :param incident_angle: tilting of the sample towards the beam (analog to rot2): in radians + :param tilt_angle: tilting of the sample orthogonal to the beam direction (analog to rot3): in radians :param int sample_orientation: 1-4, four different orientation of the fiber axis regarding the detector main axis, from 1 to 4 is +90º :param str filename: output filename in 2/3 column ascii format :param bool correctSolidAngle: correct for solid angle of each pixel if True @@ -183,8 +185,14 @@ def integrate_fiber(self, data, unit_ip = unit_ip or 'qip_nm^-1' unit_oop = unit_oop or 'qoop_nm^-1' - unit_ip = parse_fiber_unit(unit=unit_ip, sample_orientation=sample_orientation) - unit_oop = parse_fiber_unit(unit=unit_oop, sample_orientation=unit_ip.sample_orientation) + unit_ip = parse_fiber_unit(unit=unit_ip, + incident_angle=kwargs.get('incident_angle', None), + tilt_angle=kwargs.get('tilt_angle', None), + sample_orientation=sample_orientation) + unit_oop = parse_fiber_unit(unit=unit_oop, + incident_angle=unit_ip.incident_angle, + tilt_angle=unit_ip.tilt_angle, + sample_orientation=unit_ip.sample_orientation) self.reset_integrator(incident_angle=unit_ip.incident_angle, tilt_angle=unit_ip.tilt_angle, @@ -262,78 +270,7 @@ def integrate_fiber(self, data, return result - def integrate_grazing_incidence(self, data, - npt_oop=None, unit_oop=None, oop_range=None, - npt_ip=None, unit_ip=None, ip_range=None, - vertical_integration = True, - incident_angle=None, tilt_angle=None, sample_orientation=None, - filename=None, - correctSolidAngle=True, - mask=None, dummy=None, delta_dummy=None, - polarization_factor=None, dark=None, flat=None, - method=("no", "histogram", "cython"), - normalization_factor=1.0, - **kwargs): - """Calculate the integrated profile curve along a specific FiberUnit, additional inputs for incident angle, tilt angle and sample_orientation - - :param ndarray data: 2D array from the Detector/CCD camera - :param int npt_oop: number of points to be used along the out-of-plane axis - :param pyFAI.units.UnitFiber/str unit_oop: unit to describe the out-of-plane axis. If not provided, it takes qoop_nm^-1 - :param list oop_range: The lower and upper range of the out-of-plane unit. If not provided, range is simply (data.min(), data.max()). Values outside the range are ignored. Optional. - :param int npt_ip: number of points to be used along the in-plane axis - :param pyFAI.units.UnitFiber/str unit_ip: unit to describe the in-plane axis. If not provided, it takes qip_nm^-1 - :param list ip_range: The lower and upper range of the in-plane unit. If not provided, range is simply (data.min(), data.max()). Values outside the range are ignored. Optional. - :param bool vertical_integration: If True, integrates along unit_ip; if False, integrates along unit_oop - :param incident_angle: tilting of the sample towards the beam (analog to rot2): in radians - :param tilt_angle: tilting of the sample orthogonal to the beam direction (analog to rot3): in radians - :param int sample_orientation: 1-4, four different orientation of the fiber axis regarding the detector main axis, from 1 to 4 is +90º - :param str filename: output filename in 2/3 column ascii format - :param bool correctSolidAngle: correct for solid angle of each pixel if True - :param ndarray mask: array (same size as image) with 1 for masked pixels, and 0 for valid pixels - :param float dummy: value for dead/masked pixels - :param float delta_dummy: precision for dummy value - :param float polarization_factor: polarization factor between -1 (vertical) and +1 (horizontal). - * 0 for circular polarization or random, - * None for no correction, - * True for using the former correction - :param ndarray dark: dark noise image - :param ndarray flat: flat field image - :param IntegrationMethod method: IntegrationMethod instance or 3-tuple with (splitting, algorithm, implementation) - :param float normalization_factor: Value of a normalization monitor - :return: chi bins center positions and regrouped intensity - :rtype: Integrate1dResult - """ - deprecated_params = get_deprecated_params_1d(**kwargs) - npt_oop = deprecated_params.get('npt_oop', None) or npt_oop - npt_ip = deprecated_params.get('npt_ip', None) or npt_ip - unit_oop = deprecated_params.get('unit_oop', None) or unit_oop - unit_ip = deprecated_params.get('unit_ip', None) or unit_ip - oop_range = deprecated_params.get('oop_range', None) or oop_range - ip_range = deprecated_params.get('ip_range', None) or ip_range - vertical_integration = deprecated_params.get('vertical_integration', None) or vertical_integration - - unit_ip = unit_ip or 'qip_nm^-1' - unit_oop = unit_oop or 'qoop_nm^-1' - unit_ip = parse_fiber_unit(unit=unit_ip, incident_angle=incident_angle, tilt_angle=tilt_angle, sample_orientation=sample_orientation) - unit_oop = parse_fiber_unit(unit=unit_oop, incident_angle=unit_ip.incident_angle, tilt_angle=unit_ip.tilt_angle, sample_orientation=unit_ip.sample_orientation) - - self.reset_integrator(incident_angle=unit_ip.incident_angle, - tilt_angle=unit_ip.tilt_angle, - sample_orientation=unit_ip.sample_orientation) - - return self.integrate_fiber(data=data, - npt_oop=npt_oop, unit_oop=unit_oop, oop_range=oop_range, - npt_ip=npt_ip, unit_ip=unit_ip, ip_range=ip_range, - vertical_integration=vertical_integration, - sample_orientation=sample_orientation, - filename=filename, - correctSolidAngle=correctSolidAngle, - mask=mask, dummy=dummy, delta_dummy=delta_dummy, - polarization_factor=polarization_factor, dark=dark, flat=flat, - method=method, - normalization_factor=normalization_factor, - ) - + integrate_grazing_incidence = integrate_fiber integrate1d_grazing_incidence = integrate_grazing_incidence integrate1d_fiber = integrate_fiber @@ -356,6 +293,8 @@ def integrate2d_fiber(self, data, :param int npt_oop: number of points to be used along the out-of-plane axis :param pyFAI.units.UnitFiber/str unit_oop: unit to describe the out-of-plane axis. If not provided, it takes qoop_nm^-1 :param list oop_range: The lower and upper range of the out-of-plane unit. If not provided, range is simply (data.min(), data.max()). Values outside the range are ignored. Optional. + :param incident_angle: tilting of the sample towards the beam (analog to rot2): in radians + :param tilt_angle: tilting of the sample orthogonal to the beam direction (analog to rot3): in radians :param int sample_orientation: 1-4, four different orientation of the fiber axis regarding the detector main axis, from 1 to 4 is +90º :param str filename: output filename in 2/3 column ascii format :param bool correctSolidAngle: correct for solid angle of each pixel if True @@ -383,8 +322,15 @@ def integrate2d_fiber(self, data, unit_ip = unit_ip or 'qip_nm^-1' unit_oop = unit_oop or 'qoop_nm^-1' - unit_ip = parse_fiber_unit(unit=unit_ip, sample_orientation=sample_orientation) - unit_oop = parse_fiber_unit(unit=unit_oop, sample_orientation=unit_ip.sample_orientation) + unit_ip = parse_fiber_unit(unit=unit_ip, + sample_orientation=sample_orientation, + incident_angle=kwargs.get('incident_angle', None), + tilt_angle=kwargs.get('tilt_angle', None), + ) + unit_oop = parse_fiber_unit(unit=unit_oop, + incident_angle=unit_ip.incident_angle, + tilt_angle=unit_ip.tilt_angle, + sample_orientation=unit_ip.sample_orientation) self.reset_integrator(incident_angle=unit_ip.incident_angle, tilt_angle=unit_ip.tilt_angle, @@ -403,74 +349,5 @@ def integrate2d_fiber(self, data, azimuth_range=oop_range, unit=(unit_ip, unit_oop), filename=filename) - - def integrate2d_grazing_incidence(self, data, - npt_ip=1000, unit_ip=None, ip_range=None, - npt_oop=1000, unit_oop=None, oop_range=None, - incident_angle=None, tilt_angle=None, sample_orientation=None, - filename=None, - correctSolidAngle=True, - mask=None, dummy=None, delta_dummy=None, - polarization_factor=None, dark=None, flat=None, - method=("no", "histogram", "cython"), - normalization_factor=1.0, **kwargs): - """Reshapes the data pattern as a function of two FiberUnits, additional inputs for incident angle, tilt angle and sample_orientation - - :param ndarray data: 2D array from the Detector/CCD camera - :param int npt_ip: number of points to be used along the in-plane axis - :param pyFAI.units.UnitFiber/str unit_ip: unit to describe the in-plane axis. If not provided, it takes qip_nm^-1 - :param list ip_range: The lower and upper range of the in-plane unit. If not provided, range is simply (data.min(), data.max()). Values outside the range are ignored. Optional. - :param int npt_oop: number of points to be used along the out-of-plane axis - :param pyFAI.units.UnitFiber/str unit_oop: unit to describe the out-of-plane axis. If not provided, it takes qoop_nm^-1 - :param list oop_range: The lower and upper range of the out-of-plane unit. If not provided, range is simply (data.min(), data.max()). Values outside the range are ignored. Optional. - :param incident_angle: tilting of the sample towards the beam (analog to rot2): in radians - :param tilt_angle: tilting of the sample orthogonal to the beam direction (analog to rot3): in radians - :param int sample_orientation: 1-4, four different orientation of the fiber axis regarding the detector main axis, from 1 to 4 is +90º - :param str filename: output filename in 2/3 column ascii format - :param bool correctSolidAngle: correct for solid angle of each pixel if True - :param ndarray mask: array (same size as image) with 1 for masked pixels, and 0 for valid pixels - :param float dummy: value for dead/masked pixels - :param float delta_dummy: precision for dummy value - :param float polarization_factor: polarization factor between -1 (vertical) and +1 (horizontal). - * 0 for circular polarization or random, - * None for no correction, - * True for using the former correction - :param ndarray dark: dark noise image - :param ndarray flat: flat field image - :param IntegrationMethod method: IntegrationMethod instance or 3-tuple with (splitting, algorithm, implementation) - :param float normalization_factor: Value of a normalization monitor - :return: regrouped intensity and unit arrays - :rtype: Integrate2dResult - """ - deprecated_params = get_deprecated_params_2d(**kwargs) - npt_oop = deprecated_params.get('npt_oop', None) or npt_oop - npt_ip = deprecated_params.get('npt_ip', None) or npt_ip - unit_oop = deprecated_params.get('unit_oop', None) or unit_oop - unit_ip = deprecated_params.get('unit_ip', None) or unit_ip - oop_range = deprecated_params.get('oop_range', None) or oop_range - ip_range = deprecated_params.get('ip_range', None) or ip_range - - unit_ip = unit_ip or 'qip_nm^-1' - unit_oop = unit_oop or 'qoop_nm^-1' - unit_ip = parse_fiber_unit(unit=unit_ip, incident_angle=incident_angle, tilt_angle=tilt_angle, sample_orientation=sample_orientation) - unit_oop = parse_fiber_unit(unit=unit_oop, incident_angle=unit_ip.incident_angle, tilt_angle=unit_ip.tilt_angle, sample_orientation=unit_ip.sample_orientation) - - self.reset_integrator(incident_angle=unit_ip.incident_angle, - tilt_angle=unit_ip.tilt_angle, - sample_orientation=unit_ip.sample_orientation) - - if (isinstance(method, (tuple, list)) and method[0] != "no") or (isinstance(method, IntegrationMethod) and method.split != "no"): - logger.warning(f"Method {method} is using a pixel-splitting scheme. GI integration should be use WITHOUT PIXEL-SPLITTING! The results could be wrong!") - - return self.integrate2d_fiber(data=data, npt_ip=npt_ip, npt_oop=npt_oop, - unit_ip=unit_ip, unit_oop=unit_oop, - ip_range=ip_range, - oop_range=oop_range, - sample_orientation=sample_orientation, - filename=filename, - correctSolidAngle=correctSolidAngle, - mask=mask, dummy=dummy, delta_dummy=delta_dummy, - polarization_factor=polarization_factor, dark=dark, flat=flat, - method=method, - normalization_factor=normalization_factor, - ) + + integrate2d_grazing_incidence = integrate2d_fiber \ No newline at end of file From a249f163743bdd6a444379fc6bfa6e0a7350136b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 14 Nov 2024 16:04:15 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/pyFAI/integrator/fiber.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pyFAI/integrator/fiber.py b/src/pyFAI/integrator/fiber.py index ac9442ba8..4ac92f916 100644 --- a/src/pyFAI/integrator/fiber.py +++ b/src/pyFAI/integrator/fiber.py @@ -185,7 +185,7 @@ def integrate_fiber(self, data, unit_ip = unit_ip or 'qip_nm^-1' unit_oop = unit_oop or 'qoop_nm^-1' - unit_ip = parse_fiber_unit(unit=unit_ip, + unit_ip = parse_fiber_unit(unit=unit_ip, incident_angle=kwargs.get('incident_angle', None), tilt_angle=kwargs.get('tilt_angle', None), sample_orientation=sample_orientation) @@ -322,7 +322,7 @@ def integrate2d_fiber(self, data, unit_ip = unit_ip or 'qip_nm^-1' unit_oop = unit_oop or 'qoop_nm^-1' - unit_ip = parse_fiber_unit(unit=unit_ip, + unit_ip = parse_fiber_unit(unit=unit_ip, sample_orientation=sample_orientation, incident_angle=kwargs.get('incident_angle', None), tilt_angle=kwargs.get('tilt_angle', None), @@ -349,5 +349,5 @@ def integrate2d_fiber(self, data, azimuth_range=oop_range, unit=(unit_ip, unit_oop), filename=filename) - - integrate2d_grazing_incidence = integrate2d_fiber \ No newline at end of file + + integrate2d_grazing_incidence = integrate2d_fiber From 300fbe1911f459028c5851ed93dfa7c39cf20755 Mon Sep 17 00:00:00 2001 From: Jerome Kieffer Date: Wed, 20 Nov 2024 15:35:21 +0100 Subject: [PATCH 3/3] Retrigger CI --- src/pyFAI/integrator/fiber.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pyFAI/integrator/fiber.py b/src/pyFAI/integrator/fiber.py index 4ac92f916..267bd5b38 100644 --- a/src/pyFAI/integrator/fiber.py +++ b/src/pyFAI/integrator/fiber.py @@ -30,7 +30,7 @@ __contact__ = "edgar.gutierrez-fernandez@esr.fr" __license__ = "MIT" __copyright__ = "European Synchrotron Radiation Facility, Grenoble, France" -__date__ = "14/11/2024" +__date__ = "20/11/2024" __status__ = "stable" __docformat__ = 'restructuredtext'