Skip to content

Commit

Permalink
Fix ROI signal axes. Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kritvei committed Jul 3, 2024
1 parent e9ff520 commit fafd595
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rsciio/quantumdetector/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def parse_file(self, path):
raise TypeError("`path` must be a str or a buffer.")

# read detector size
self.merlin_size = (int(head[4]), int(head[5]))
self.merlin_size = (int(head[5]), int(head[4]))

# test if RAW
if head[6] == "R64": # pragma: no cover
Expand Down
Binary file not shown.
29 changes: 29 additions & 0 deletions rsciio/tests/test_quantumdetector.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
TEST_DATA_DIR = Path(__file__).parent / "data" / "quantumdetector"
ZIP_FILE = TEST_DATA_DIR / "Merlin_Single_Quad.zip"
ZIP_FILE2 = TEST_DATA_DIR / "Merlin_navigation4x2_ROI.zip"
ZIP_FILE3 = TEST_DATA_DIR / 'Merlin_navigation4x2_signalNx256_ROI.zip'
TEST_DATA_DIR_UNZIPPED = TEST_DATA_DIR / "unzipped"


Expand All @@ -57,6 +58,9 @@
for depth in [1, 6, 12, 24]
]

SIGNAL_ROI_FNAME_LIST = ['002_merlin_test_roi_sig256x128_nav4x2_hot_pixel_52x_39y.mib',
'003_merlin_test_roi_sig256x64_nav4x2_hot_pixel_52x_39y.mib']


def filter_list(fname_list, string):
return [fname for fname in fname_list if string in fname]
Expand All @@ -71,6 +75,10 @@ def setup_module():
if ZIP_FILE2.exists():
with zipfile.ZipFile(ZIP_FILE2, "r") as zipped:
zipped.extractall(TEST_DATA_DIR_UNZIPPED)
if ZIP_FILE3.exists():
with zipfile.ZipFile(ZIP_FILE3, "r") as zipped:
zipped.extractall(TEST_DATA_DIR_UNZIPPED)



def teardown_module():
Expand Down Expand Up @@ -412,3 +420,24 @@ def test_distributed(lazy):
s.compute()
s2.compute()
np.testing.assert_array_equal(s.data, s2.data)


@pytest.mark.parametrize("fname", SIGNAL_ROI_FNAME_LIST)
def test_hot_pixel_signal_ROI(fname):
s = hs.load(TEST_DATA_DIR_UNZIPPED / fname)
for i in s:
for j in i:
data = j.data
xy = np.argwhere(data==data.max())
assert len(xy) == 1
coord_shifted = np.array(*xy) - np.array([data.shape[0], 0])
assert np.all(coord_shifted == np.array([-40,52]))

@pytest.mark.parametrize('fname', SIGNAL_ROI_FNAME_LIST)
def test_signal_shape_ROI(fname):
s = hs.load(TEST_DATA_DIR_UNZIPPED / fname)
assert s.axes_manager.navigation_shape == (4, 2)
if 'sig256x64' in fname:
assert s.axes_manager.signal_shape == (256,64)
if 'sig256x128' in fname:
assert s.axes_manager.signal_shape == (256,128)

0 comments on commit fafd595

Please sign in to comment.