From 7d566dc710b43341097906f1e436059f97af5c44 Mon Sep 17 00:00:00 2001 From: edgar1993a Date: Thu, 30 Jan 2025 14:12:51 +0100 Subject: [PATCH 1/8] polar angles api --- src/pyFAI/integrator/fiber.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/pyFAI/integrator/fiber.py b/src/pyFAI/integrator/fiber.py index f12760b24..d7ff752e3 100644 --- a/src/pyFAI/integrator/fiber.py +++ b/src/pyFAI/integrator/fiber.py @@ -376,3 +376,28 @@ def integrate2d_fiber(self, data, filename=filename) integrate2d_grazing_incidence = integrate2d_fiber + + def integrate2d_polar(self, polar_unit="deg", radial_unit="nm^-1", rotate=False, **kwargs): + unit_ip = "chigi_rad" if polar_unit == "rad" else "chigi_deg" + unit_oop = "qtot_A^-1" if radial_unit == "A^-1" else "qtot_nm^-1" + + if rotate: + kwargs["unit_ip"] = unit_oop + kwargs["unit_oop"] = unit_ip + else: + kwargs["unit_ip"] = unit_ip + kwargs["unit_oop"] = unit_oop + + return self.integrate2d_grazing_incidence(**kwargs) + + def integrate2d_exitangles(self, unit="deg", **kwargs): + if unit == "rad": + unit_ip = "exit_angle_horz_rad" + unit_oop = "exit_angle_vert_rad" + else: + unit_ip = "exit_angle_horz_deg" + unit_oop = "exit_angle_vert_deg" + + kwargs["unit_ip"] = unit_ip + kwargs["unit_oop"] = unit_oop + return self.integrate2d_grazing_incidence(**kwargs) \ No newline at end of file From ea39a83142d118912d9ae96d31621f31a24d170e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 30 Jan 2025 13:14:04 +0000 Subject: [PATCH 2/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/pyFAI/integrator/fiber.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pyFAI/integrator/fiber.py b/src/pyFAI/integrator/fiber.py index d7ff752e3..3b4d6e618 100644 --- a/src/pyFAI/integrator/fiber.py +++ b/src/pyFAI/integrator/fiber.py @@ -389,7 +389,7 @@ def integrate2d_polar(self, polar_unit="deg", radial_unit="nm^-1", rotate=False, kwargs["unit_oop"] = unit_oop return self.integrate2d_grazing_incidence(**kwargs) - + def integrate2d_exitangles(self, unit="deg", **kwargs): if unit == "rad": unit_ip = "exit_angle_horz_rad" @@ -400,4 +400,4 @@ def integrate2d_exitangles(self, unit="deg", **kwargs): kwargs["unit_ip"] = unit_ip kwargs["unit_oop"] = unit_oop - return self.integrate2d_grazing_incidence(**kwargs) \ No newline at end of file + return self.integrate2d_grazing_incidence(**kwargs) From 870f69b478d2368ef26a40a87d48ed27daefb893 Mon Sep 17 00:00:00 2001 From: edgar1993a Date: Thu, 30 Jan 2025 14:35:00 +0100 Subject: [PATCH 3/8] docs --- src/pyFAI/integrator/fiber.py | 51 +++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/src/pyFAI/integrator/fiber.py b/src/pyFAI/integrator/fiber.py index d7ff752e3..88f47bee9 100644 --- a/src/pyFAI/integrator/fiber.py +++ b/src/pyFAI/integrator/fiber.py @@ -44,6 +44,35 @@ from ..units import parse_fiber_unit from ..utils.decorators import deprecated_warning +docs_params_integrate2d = """\ + :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-8, orientation of the fiber axis according to EXIF orientation values (see def sample_orientation) + :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 +""" + + def get_deprecated_params_1d(**kwargs) -> dict: deprecated = {} if "npt_output" in kwargs: @@ -377,8 +406,16 @@ def integrate2d_fiber(self, data, integrate2d_grazing_incidence = integrate2d_fiber - def integrate2d_polar(self, polar_unit="deg", radial_unit="nm^-1", rotate=False, **kwargs): - unit_ip = "chigi_rad" if polar_unit == "rad" else "chigi_deg" + def integrate2d_polar(self, polar_degrees=True, radial_unit="nm^-1", rotate=False, **kwargs): + f"""Reshapes the data pattern as a function of polar angle=arctan(qOOP / qIP) versus q modulus + + :param polar_degrees bool: if True, polar angle in degrees, else in radians + :param radial_unit str: unit of q modulus: nm^-1 or A^-1 + :param rotate bool: if False, polar_angle vs q, if True q vs polar_angle + + {docs_params_integrate2d} + """ + unit_ip = "chigi_deg" if polar_degrees else "chigi_rad" unit_oop = "qtot_A^-1" if radial_unit == "A^-1" else "qtot_nm^-1" if rotate: @@ -387,11 +424,15 @@ def integrate2d_polar(self, polar_unit="deg", radial_unit="nm^-1", rotate=False, else: kwargs["unit_ip"] = unit_ip kwargs["unit_oop"] = unit_oop - return self.integrate2d_grazing_incidence(**kwargs) - def integrate2d_exitangles(self, unit="deg", **kwargs): - if unit == "rad": + def integrate2d_exitangles(self, angle_degrees=True, **kwargs): + f"""Reshapes the data pattern as a function of exit angles with the origin at the sample horizon + + :param angle_degrees bool: if True, exit angles in degrees, else in radians + {docs_params_integrate2d} + """ + if angle_degrees: unit_ip = "exit_angle_horz_rad" unit_oop = "exit_angle_vert_rad" else: From 29fbb984c3b338517adefca8a4fba965720d7679 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 30 Jan 2025 13:35:59 +0000 Subject: [PATCH 4/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/pyFAI/integrator/fiber.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pyFAI/integrator/fiber.py b/src/pyFAI/integrator/fiber.py index dfc792043..42bafb960 100644 --- a/src/pyFAI/integrator/fiber.py +++ b/src/pyFAI/integrator/fiber.py @@ -408,7 +408,7 @@ def integrate2d_fiber(self, data, def integrate2d_polar(self, polar_degrees=True, radial_unit="nm^-1", rotate=False, **kwargs): f"""Reshapes the data pattern as a function of polar angle=arctan(qOOP / qIP) versus q modulus - + :param polar_degrees bool: if True, polar angle in degrees, else in radians :param radial_unit str: unit of q modulus: nm^-1 or A^-1 :param rotate bool: if False, polar_angle vs q, if True q vs polar_angle @@ -425,10 +425,10 @@ def integrate2d_polar(self, polar_degrees=True, radial_unit="nm^-1", rotate=Fals kwargs["unit_ip"] = unit_ip kwargs["unit_oop"] = unit_oop return self.integrate2d_grazing_incidence(**kwargs) - + def integrate2d_exitangles(self, angle_degrees=True, **kwargs): f"""Reshapes the data pattern as a function of exit angles with the origin at the sample horizon - + :param angle_degrees bool: if True, exit angles in degrees, else in radians {docs_params_integrate2d} """ From 8921bf985812b0bc4830adc477341d2e9d32c34c Mon Sep 17 00:00:00 2001 From: edgar1993a Date: Thu, 30 Jan 2025 14:52:44 +0100 Subject: [PATCH 5/8] docs --- src/pyFAI/integrator/fiber.py | 51 ++++++++++------------------------- 1 file changed, 14 insertions(+), 37 deletions(-) diff --git a/src/pyFAI/integrator/fiber.py b/src/pyFAI/integrator/fiber.py index 42bafb960..b984fe82a 100644 --- a/src/pyFAI/integrator/fiber.py +++ b/src/pyFAI/integrator/fiber.py @@ -44,35 +44,6 @@ from ..units import parse_fiber_unit from ..utils.decorators import deprecated_warning -docs_params_integrate2d = """\ - :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-8, orientation of the fiber axis according to EXIF orientation values (see def sample_orientation) - :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 -""" - - def get_deprecated_params_1d(**kwargs) -> dict: deprecated = {} if "npt_output" in kwargs: @@ -407,16 +378,16 @@ def integrate2d_fiber(self, data, integrate2d_grazing_incidence = integrate2d_fiber def integrate2d_polar(self, polar_degrees=True, radial_unit="nm^-1", rotate=False, **kwargs): - f"""Reshapes the data pattern as a function of polar angle=arctan(qOOP / qIP) versus q modulus + """Reshapes the data pattern as a function of polar angle=arctan(qOOP / qIP) versus q modulus. :param polar_degrees bool: if True, polar angle in degrees, else in radians :param radial_unit str: unit of q modulus: nm^-1 or A^-1 :param rotate bool: if False, polar_angle vs q, if True q vs polar_angle - {docs_params_integrate2d} + Calls method integrate2d_fiber -> """ - unit_ip = "chigi_deg" if polar_degrees else "chigi_rad" - unit_oop = "qtot_A^-1" if radial_unit == "A^-1" else "qtot_nm^-1" + unit_oop = "chigi_deg" if polar_degrees else "chigi_rad" + unit_ip = "qtot_A^-1" if radial_unit == "A^-1" else "qtot_nm^-1" if rotate: kwargs["unit_ip"] = unit_oop @@ -424,13 +395,16 @@ def integrate2d_polar(self, polar_degrees=True, radial_unit="nm^-1", rotate=Fals else: kwargs["unit_ip"] = unit_ip kwargs["unit_oop"] = unit_oop - return self.integrate2d_grazing_incidence(**kwargs) + return self.integrate2d_fiber(**kwargs) + + integrate2d_polar.__doc__ += "\n" + integrate2d_fiber.__doc__ def integrate2d_exitangles(self, angle_degrees=True, **kwargs): - f"""Reshapes the data pattern as a function of exit angles with the origin at the sample horizon + """Reshapes the data pattern as a function of exit angles with the origin at the sample horizon :param angle_degrees bool: if True, exit angles in degrees, else in radians - {docs_params_integrate2d} + + Calls method integrate2d_fiber -> """ if angle_degrees: unit_ip = "exit_angle_horz_rad" @@ -441,4 +415,7 @@ def integrate2d_exitangles(self, angle_degrees=True, **kwargs): kwargs["unit_ip"] = unit_ip kwargs["unit_oop"] = unit_oop - return self.integrate2d_grazing_incidence(**kwargs) + return self.integrate2d_fiber(**kwargs) + + integrate2d_exitangles.__doc__ += "\n" + integrate2d_fiber.__doc__ + From 0dfc96fdf7c3993ae2c516c8d7404923629d06fb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 30 Jan 2025 13:53:11 +0000 Subject: [PATCH 6/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/pyFAI/integrator/fiber.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/pyFAI/integrator/fiber.py b/src/pyFAI/integrator/fiber.py index b984fe82a..4009b7efa 100644 --- a/src/pyFAI/integrator/fiber.py +++ b/src/pyFAI/integrator/fiber.py @@ -396,7 +396,7 @@ def integrate2d_polar(self, polar_degrees=True, radial_unit="nm^-1", rotate=Fals kwargs["unit_ip"] = unit_ip kwargs["unit_oop"] = unit_oop return self.integrate2d_fiber(**kwargs) - + integrate2d_polar.__doc__ += "\n" + integrate2d_fiber.__doc__ def integrate2d_exitangles(self, angle_degrees=True, **kwargs): @@ -416,6 +416,5 @@ def integrate2d_exitangles(self, angle_degrees=True, **kwargs): kwargs["unit_ip"] = unit_ip kwargs["unit_oop"] = unit_oop return self.integrate2d_fiber(**kwargs) - + integrate2d_exitangles.__doc__ += "\n" + integrate2d_fiber.__doc__ - From b9be5317c5c0f04dcc6617813547f5e80c5ddce5 Mon Sep 17 00:00:00 2001 From: edgar1993a Date: Thu, 30 Jan 2025 15:13:20 +0100 Subject: [PATCH 7/8] integrate1d apis --- src/pyFAI/integrator/fiber.py | 49 ++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/src/pyFAI/integrator/fiber.py b/src/pyFAI/integrator/fiber.py index b984fe82a..9b40226ad 100644 --- a/src/pyFAI/integrator/fiber.py +++ b/src/pyFAI/integrator/fiber.py @@ -407,15 +407,58 @@ def integrate2d_exitangles(self, angle_degrees=True, **kwargs): Calls method integrate2d_fiber -> """ if angle_degrees: - unit_ip = "exit_angle_horz_rad" - unit_oop = "exit_angle_vert_rad" - else: unit_ip = "exit_angle_horz_deg" unit_oop = "exit_angle_vert_deg" + else: + unit_ip = "exit_angle_horz_rad" + unit_oop = "exit_angle_vert_rad" kwargs["unit_ip"] = unit_ip kwargs["unit_oop"] = unit_oop return self.integrate2d_fiber(**kwargs) integrate2d_exitangles.__doc__ += "\n" + integrate2d_fiber.__doc__ + + def integrate1d_polar(self, polar_degrees=True, radial_unit="nm^-1", radial_integration=False, **kwargs): + """Calculate the integrated profile curve along the polar angle=arctan(qOOP / qIP) or as a function of the polar angle along q modulus + + :param polar_degrees bool: if True, polar angle in degrees, else in radians + :param radial_unit str: unit of q modulus: nm^-1 or A^-1 + :param radial_integration bool: if False, the output profile is I vs q, if True (I vs polar_angle) + + Calls method integrate_fiber -> + """ + unit_oop = "chigi_deg" if polar_degrees else "chigi_rad" + unit_ip = "qtot_A^-1" if radial_unit == "A^-1" else "qtot_nm^-1" + kwargs["unit_ip"] = unit_ip + kwargs["unit_oop"] = unit_oop + if radial_integration: + kwargs["vertical_integration"] = True + else: + kwargs["vertical_integration"] = False + return self.integrate_fiber(**kwargs) + + integrate1d_polar.__doc__ += "\n" + integrate_fiber.__doc__ + + def integrate1d_exitangles(self, angle_degrees=True, vertical_integration=True, **kwargs): + """Calculate the integrated profile curve along the one of the exit angles (with the origin at the sample horizon) + + :param angle_degrees bool: if True, exit angles in degrees, else in radians + :param vertical_integration bool: if True, the output profile is I vs vertical_angle, if False (I vs horizontal_angle) + + Calls method integrate_fiber -> + """ + if angle_degrees: + unit_ip = "exit_angle_horz_deg" + unit_oop = "exit_angle_vert_deg" + else: + unit_ip = "exit_angle_horz_rad" + unit_oop = "exit_angle_vert_rad" + + kwargs["unit_ip"] = unit_ip + kwargs["unit_oop"] = unit_oop + kwargs["vertical_integration"] = vertical_integration + return self.integrate_fiber(**kwargs) + integrate1d_exitangles.__doc__ += "\n" + integrate_fiber.__doc__ + \ No newline at end of file From 38e41f2d780fb92264f3f343ac27cfb410959a61 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 30 Jan 2025 14:15:29 +0000 Subject: [PATCH 8/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/pyFAI/integrator/fiber.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/pyFAI/integrator/fiber.py b/src/pyFAI/integrator/fiber.py index ecb712db0..09a864648 100644 --- a/src/pyFAI/integrator/fiber.py +++ b/src/pyFAI/integrator/fiber.py @@ -437,7 +437,7 @@ def integrate1d_polar(self, polar_degrees=True, radial_unit="nm^-1", radial_inte else: kwargs["vertical_integration"] = False return self.integrate_fiber(**kwargs) - + integrate1d_polar.__doc__ += "\n" + integrate_fiber.__doc__ def integrate1d_exitangles(self, angle_degrees=True, vertical_integration=True, **kwargs): @@ -459,6 +459,5 @@ def integrate1d_exitangles(self, angle_degrees=True, vertical_integration=True, kwargs["unit_oop"] = unit_oop kwargs["vertical_integration"] = vertical_integration return self.integrate_fiber(**kwargs) - + integrate1d_exitangles.__doc__ += "\n" + integrate_fiber.__doc__ - \ No newline at end of file