-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2451 from kif/2449_normalize_azimuth_range
Normalize azimuthal range
- Loading branch information
Showing
2 changed files
with
42 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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' | ||
|
||
|
@@ -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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]) | ||
# | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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) | ||
|
@@ -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): | ||
""" | ||
|
@@ -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)) | ||
|