Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize azimuthal range #2451

Merged
merged 2 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/pyFAI/geometry/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
__contact__ = "[email protected]"
__license__ = "MIT"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
__date__ = "19/02/2025"
__date__ = "20/02/2025"
__status__ = "production"
__docformat__ = 'restructuredtext'

Expand Down Expand Up @@ -260,8 +260,21 @@ def normalize_azimuth_range(self, azimuth_range):
:param azimuth_range: 2-tuple of float in degrees
:return: 2-tuple of float in radians in a range such to avoid the discontinuity
"""
unkn = 0
if azimuth_range is None:
unkn = 2
else:
if azimuth_range[0] is None:
unkn += 1
if azimuth_range[-1] is None:
unkn += 1
if unkn == 2:
return
elif unkn == 1:
max_range = (-180, 180) if self.chiDiscAtPi else (0,360)
azimuth_range = (max_range[0] if azimuth_range[0] is None else azimuth_range[0],
max_range[-1] if azimuth_range[-1] is None else azimuth_range[-1])

azimuth_range = tuple(deg2rad(azimuth_range[i], self.chiDiscAtPi) for i in (0, -1))
if azimuth_range[1] <= azimuth_range[0]:
azimuth_range = (azimuth_range[0], azimuth_range[1] + TWO_PI)
Expand Down
37 changes: 28 additions & 9 deletions src/pyFAI/test/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Project: Azimuthal integration
# https://github.com/silx-kit/pyFAI
#
# Copyright (C) 2015-2024 European Synchrotron Radiation Facility, Grenoble, France
# Copyright (C) 2015-2025 European Synchrotron Radiation Facility, Grenoble, France
#
# Principal author: Jérôme Kieffer ([email protected])
#
Expand Down Expand Up @@ -34,7 +34,7 @@
__contact__ = "[email protected]"
__license__ = "MIT"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
__date__ = "09/10/2024"
__date__ = "20/02/2025"

import unittest
import random
Expand All @@ -46,6 +46,7 @@
import os.path
import json
import fabio
from math import pi
from . import utilstest
from ..io.ponifile import PoniFile
from .. import geometry
Expand Down Expand Up @@ -185,14 +186,14 @@ def test_flat(self):
self.assertGreater(one.min() - 1.0, -1e-10, f"path: {path} cos2+sin2>0.99")


class TestBug88SolidAngle(unittest.TestCase):
"""
Test case for solid angle where data got modified inplace.
class TestRegression(unittest.TestCase):

https://github.com/silx-kit/pyFAI/issues/88
"""
def testBug88SolidAngle(self):
"""
Test case for solid angle where data got modified inplace.

def testSolidAngle(self):
https://github.com/silx-kit/pyFAI/issues/88
"""
method = ("no", "histogram", "python")
ai = AzimuthalIntegrator(dist=0.001, detector="Imxpad S10", wavelength=1e-10)
img = numpy.ones(ai.detector.shape, dtype=numpy.float32)
Expand All @@ -203,6 +204,24 @@ def testSolidAngle(self):
self.assertAlmostEqual(f, 1, 5, "uncorrected flat data are unchanged")
self.assertNotAlmostEqual(f, t, 1, "corrected and uncorrected flat data are different")

def testBug2449NormalizeAzimuthRange(self):

ai0 = AzimuthalIntegrator(dist=0.001, detector="Imxpad S10", wavelength=1e-10)
ai0.setChiDiscAtZero()
self.assertEqual(ai0.normalize_azimuth_range((90, -90)), (pi/2, 3*pi/2))
self.assertEqual(ai0.normalize_azimuth_range(None), None)
self.assertEqual(ai0.normalize_azimuth_range([None, None]), None)
self.assertEqual(ai0.normalize_azimuth_range([None, 180]), (0, pi))
self.assertEqual(ai0.normalize_azimuth_range([180, None]), (pi, 2*pi))

ai1 = AzimuthalIntegrator(dist=0.001, detector="Imxpad S10", wavelength=1e-10)
ai1.setChiDiscAtPi()
self.assertEqual(ai1.normalize_azimuth_range((-90, 90)), (-pi/2, pi/2))
self.assertEqual(ai1.normalize_azimuth_range(None), None)
self.assertEqual(ai1.normalize_azimuth_range([None, None]), None)
self.assertEqual(ai1.normalize_azimuth_range([None, 0]), (-pi, 0))
self.assertEqual(ai1.normalize_azimuth_range([0, None]), (0, pi))


class TestRecprocalSpacingSquarred(unittest.TestCase):
"""
Expand Down Expand Up @@ -1181,7 +1200,7 @@ def suite():
testsuite = unittest.TestSuite()
testsuite.addTest(loader(TestBugRegression))
testsuite.addTest(loader(TestSolidAngle))
testsuite.addTest(loader(TestBug88SolidAngle))
testsuite.addTest(loader(TestRegression))
testsuite.addTest(loader(TestRecprocalSpacingSquarred))
testsuite.addTest(loader(TestCalcFrom))
testsuite.addTest(loader(TestGeometry))
Expand Down