Skip to content

Commit

Permalink
Add test for pseudo "SEM" data
Browse files Browse the repository at this point in the history
  • Loading branch information
nem1234 committed Nov 24, 2022
1 parent a311f0f commit 512628c
Showing 1 changed file with 43 additions and 17 deletions.
60 changes: 43 additions & 17 deletions rsciio/tests/test_jeol.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,23 +560,49 @@ def test_seq_eds_files():
with tempfile.TemporaryDirectory() as tmpdir:
with zipfile.ZipFile(test_file, "r") as zipped:
zipped.extractall(tmpdir)
s = hs.load(Path(tmpdir) / "1" / "1.ASW")
# check if three subfiles are in file (img, eds, eds)
assert len(s) == 3
# check positional information in subfiles
for i, p in enumerate(pos):
sampleinfo = s[i].original_metadata["asw"]["SampleInfo"]["0"]
viewinfo = sampleinfo["ViewInfo"]["0"]
np.testing.assert_allclose(viewinfo["PositionMM2"], pos0)
viewdata_asw = viewinfo["ViewData"]
viewdata = s[i].original_metadata["asw_viewdata"]
np.testing.assert_allclose(viewdata["PositionMM2"], p)
np.testing.assert_allclose(
viewdata["PositionMM2"], viewdata_asw[i]["PositionMM2"]
)
assert viewdata["Memo"] == memo[i]
assert isinstance(s[1], hs.signals.EDSTEMSpectrum)
assert isinstance(s[2], hs.signals.EDSTEMSpectrum)

# test reading sequential acuired EDS spectrum
s = hs.load(Path(tmpdir) / "1" / "1.ASW")
# check if three subfiles are in file (img, eds, eds)
assert len(s) == 3
# check positional information in subfiles
for i, p in enumerate(pos):
sampleinfo = s[i].original_metadata["asw"]["SampleInfo"]["0"]
viewinfo = sampleinfo["ViewInfo"]["0"]
np.testing.assert_allclose(viewinfo["PositionMM2"], pos0)
viewdata_asw = viewinfo["ViewData"]
viewdata = s[i].original_metadata["asw_viewdata"]
np.testing.assert_allclose(viewdata["PositionMM2"], p)
np.testing.assert_allclose(
viewdata["PositionMM2"], viewdata_asw[i]["PositionMM2"]
)
assert viewdata["Memo"] == memo[i]
assert isinstance(s[1], hs.signals.EDSTEMSpectrum)
assert isinstance(s[2], hs.signals.EDSTEMSpectrum)

# test read for pseudo SEM eds/img data
sub_dir = Path(tmpdir) / "1" / "Sample" / "00_View002"
test_files = ["View002_0000000.img", "View002_0000001.eds"]

# rewrite AccV 200 kV to 20 kV to generate pseudo SEM data
# .img
with open(sub_dir / test_files[0], "rb") as f:
data = bytearray(f.read())
data[0x75BC] = 0xA0
data[0x75BD] = 0x41
with open(sub_dir / ('x' + test_files[0]), "wb") as f:
f.write(data)
s = hs.load( sub_dir / ('x' + test_files[0]) )
assert "SEM" in s.metadata["Acquisition_instrument"]

# .eds
with open(sub_dir / test_files[1], "rb") as f:
data = bytearray(f.read())
data[0x4B13] = 0x34
with open(sub_dir / ('x' + test_files[1]), "wb") as f:
f.write(data)
s = hs.load(sub_dir / ('x' + test_files[1]) )
assert isinstance(s, hs.signals.EDSSEMSpectrum)


def test_frame_start_index():
Expand Down

0 comments on commit 512628c

Please sign in to comment.