Skip to content

Commit

Permalink
Update tests for differently rounded center coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
viljarjf committed Apr 10, 2024
1 parent 8b56771 commit a784fde
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion pyxem/tests/utils/test_calibration_utils.py
Expand Up @@ -90,16 +90,20 @@ def test_set_failure(self, calibration):
calibration.detector(pixel_size=0.1, detector_distance=1)
calibration.beam_energy = 200
calibration.detector(pixel_size=0.1, detector_distance=1)
# The center, in pixel coordinates, is (4.5, 4.5)
# When using a detector, this gets rounded down to 4
assert calibration.center == [4, 4]
calibration.detector(
pixel_size=0.1, detector_distance=1, beam_energy=200, units="k_nm^-1"
)
assert calibration.flat_ewald is False
assert calibration.center == [4, 4]
with pytest.raises(ValueError):
calibration(scale=0.01)
assert calibration.scale is None
with pytest.raises(ValueError):
calibration(center=(5, 5))
assert calibration.center == [5, 5]
assert calibration.center == [4, 4]

with pytest.raises(ValueError):
calibration.detector(pixel_size=0.1, detector_distance=1, units="nm^-1")
Expand Down
4 changes: 2 additions & 2 deletions pyxem/utils/calibration.py
Expand Up @@ -230,7 +230,7 @@ def detector(
)

if center is None:
center = [(ax.max() - ax.min()) / 2 for ax in self.axes]
center = [(ax.size - 1) / 2 for ax in self.axes]

def translate_pixel_coords(px: np.ndarray) -> np.ndarray:
coord = pixel_size * px
Expand Down Expand Up @@ -305,7 +305,7 @@ def pixel_extent(self):
"""
if self.flat_ewald:
extents = []
for ax, scale in zip(self.axes, self.scale):
for ax, scale in zip(self.axes, self.scale):
left = ax - scale / 2
right = ax + scale / 2
extent = np.stack((left, right))
Expand Down

0 comments on commit a784fde

Please sign in to comment.