From 9423716087f52c545b0a91036e83502d28dc96b6 Mon Sep 17 00:00:00 2001 From: Takashi Nemoto Date: Mon, 15 May 2023 19:39:43 +0900 Subject: [PATCH 1/3] Add minimum code to support JEOL EPMA .map file --- rsciio/jeol/_api.py | 52 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/rsciio/jeol/_api.py b/rsciio/jeol/_api.py index ba8a45aa8..e6473a531 100644 --- a/rsciio/jeol/_api.py +++ b/rsciio/jeol/_api.py @@ -152,6 +152,50 @@ def _read_asw(filename, **kwargs): file_reader.__doc__ %= (FILENAME_DOC, LAZY_DOC, RETURNS_DOC) +def _read_epma_img(filename, **kwargs): + with open(filename, "br") as fd: + file_magic = np.fromfile(fd, " Date: Tue, 16 May 2023 18:08:01 +0900 Subject: [PATCH 2/3] Add comments Add test for epma image Replace tmpdir with pytest's tmp_path --- rsciio/jeol/_api.py | 27 ++++- rsciio/tests/test_jeol.py | 232 ++++++++++++++++++++------------------ 2 files changed, 142 insertions(+), 117 deletions(-) diff --git a/rsciio/jeol/_api.py b/rsciio/jeol/_api.py index e6473a531..0a73de14f 100644 --- a/rsciio/jeol/_api.py +++ b/rsciio/jeol/_api.py @@ -153,9 +153,23 @@ def _read_asw(filename, **kwargs): file_reader.__doc__ %= (FILENAME_DOC, LAZY_DOC, RETURNS_DOC) def _read_epma_img(filename, **kwargs): + """ + Parameters + ---------- + filename : str + img file name + kwargs : + not used + + Returns + ------- + image_list : list of images(dict) + (Always len(image_list) == 1) + None if image is not an EPMA map. + """ with open(filename, "br") as fd: file_magic = np.fromfile(fd, " Date: Tue, 16 May 2023 18:25:14 +0900 Subject: [PATCH 3/3] Make lint happy --- rsciio/jeol/_api.py | 1 + rsciio/tests/test_jeol.py | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/rsciio/jeol/_api.py b/rsciio/jeol/_api.py index 0a73de14f..89a445f75 100644 --- a/rsciio/jeol/_api.py +++ b/rsciio/jeol/_api.py @@ -211,6 +211,7 @@ def _read_epma_img(filename, **kwargs): } return [dictionary] + def _read_img(filename, **kwargs): """ Parameters diff --git a/rsciio/tests/test_jeol.py b/rsciio/tests/test_jeol.py index 5a6946c04..2a70e273f 100644 --- a/rsciio/tests/test_jeol.py +++ b/rsciio/tests/test_jeol.py @@ -702,20 +702,21 @@ def test_frame_start_index(tmp_path): data[0x1117] = 0x41 with open(test_file, "wb") as f: f.write(data) - s = hs.load( - test_file, downsample=[32, 32], rebin_energy=512, SI_dtype=np.int32 - ) + s = hs.load(test_file, downsample=[32, 32], rebin_energy=512, SI_dtype=np.int32) assert s.metadata["Signal"]["signal_type"] == "EDS_SEM" + def test_epma_map(tmp_path): - EPMA_HEADER = b'\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00' \ - b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + EPMA_HEADER = ( + b'\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00' + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + ) img_size = 256 test_file = Path(tmp_path) / "epma.map" vals = np.arange(img_size * img_size, dtype=np.double) with open(test_file, "wb") as f: f.write(EPMA_HEADER) - vals.tofile(f, '') + vals.tofile(f, "") s = hs.load(test_file) assert s.metadata.Signal.signal_type == "EPMA" for y in range(img_size):