Skip to content

Commit

Permalink
Add test for azimuthal range
Browse files Browse the repository at this point in the history
  • Loading branch information
viljarjf committed Apr 19, 2024
1 parent 945ca16 commit b3bfb85
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions pyxem/tests/signals/test_diffraction2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,19 @@ def ones(self):
ones_diff.unit = "2th_deg"
return ones_diff

@pytest.fixture
def arange(self):
# signal looks as follows:
# 0 1
# 2 3
arange_diff = Diffraction2D(data=np.arange(4).reshape(2, 2))
arange_diff.axes_manager.signal_axes[0].scale = 1
arange_diff.axes_manager.signal_axes[1].scale = 1
arange_diff.axes_manager.signal_axes[0].name = "kx"
arange_diff.axes_manager.signal_axes[1].name = "ky"
arange_diff.unit = "2th_deg"
return arange_diff

@pytest.fixture
def ring(self):
ring_pattern = Diffraction2D(data=np.ones(shape=(100, 100)))
Expand Down Expand Up @@ -607,6 +620,44 @@ def test_internal_azimuthal_integration_data_range(self, corner, shape):

assert np.allclose(np.nanmax(pol.data), max_val)

# polar unwrapping `arange` should look like [3 1 0 2]
# since data looks like:
# 0 1
# 2 3
# and the data gets unwrapped from the center and downwards, using the right hand rule
@pytest.mark.parametrize(
[
"azimuthal_range",
"expected_output",
],
[
[
(0 * np.pi / 2, 1 * np.pi / 2),
3,
],
[
(1 * np.pi / 2, 2 * np.pi / 2),
1,
],
[
(2 * np.pi / 2, 3 * np.pi / 2),
0,
],
[
(3 * np.pi / 2, 4 * np.pi / 2),
2,
],
],
)
def test_azimuthal_integration_range(
self, arange, azimuthal_range, expected_output
):
arange.calibrate.center = None # set center
quadrant = arange.get_azimuthal_integral2d(
npt=10, npt_azim=10, azimuth_range=azimuthal_range, mean=True
)
assert np.allclose(quadrant.data[~np.isnan(quadrant.data)], expected_output)


class TestPyFAIIntegration:
@pytest.fixture
Expand Down

0 comments on commit b3bfb85

Please sign in to comment.