Skip to content

Commit

Permalink
Improve .emi sidecar file support in FormatSER (#354)
Browse files Browse the repository at this point in the history
* Read compressed .emi files by opening with Format.open_file
* Don't print from read_emi if the file can't be found
  • Loading branch information
dagewa authored Apr 30, 2021
1 parent 9a45d44 commit b88124b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
17 changes: 5 additions & 12 deletions format/FormatSER.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@


# The read_emi and _parseEntry_emi functions are taken from openNCEM project
# under the terms of the MIT license.
# and modified here under the terms of the MIT license.
#
# Copyright 2019 the Ncempy developers
#
Expand Down Expand Up @@ -65,16 +65,9 @@ def read_emi(filename):
else:
raise TypeError("Filename is supposed to be a string or pathlib.Path")

# try opening the file
try:
# open file for reading bytes, as binary and text are intermixed
with open(filename, "rb") as f_emi:
emi_data = f_emi.read()
except IOError:
print('Error reading file: "{}"'.format(filename))
raise
except Exception:
raise
# Format.open provides transparent decompression
with Format.open_file(filename, "rb") as f_emi:
emi_data = f_emi.read()

# dict to store _emi stuff
_emi = {}
Expand Down Expand Up @@ -255,7 +248,7 @@ def _read_metadata(image_file):
hd["ArraySizeY"] = struct.unpack("<I", f.read(4))[0]

try:
emi = read_emi(os.path.splitext(image_file)[0] + ".emi")
emi = read_emi(image_file.replace(".ser", ".emi"))
hd.update(emi)
except FileNotFoundError:
pass
Expand Down
1 change: 1 addition & 0 deletions newsfragments/354.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improved support for ``.emi`` sidecar files in ``FormatSER``.

0 comments on commit b88124b

Please sign in to comment.