From b88124b485fc73915aa4ff0f8adcb1b260d04318 Mon Sep 17 00:00:00 2001 From: David Waterman Date: Fri, 30 Apr 2021 14:38:42 +0100 Subject: [PATCH] Improve .emi sidecar file support in FormatSER (#354) * Read compressed .emi files by opening with Format.open_file * Don't print from read_emi if the file can't be found --- format/FormatSER.py | 17 +++++------------ newsfragments/354.feature | 1 + 2 files changed, 6 insertions(+), 12 deletions(-) create mode 100644 newsfragments/354.feature diff --git a/format/FormatSER.py b/format/FormatSER.py index ed23f6643..9f507721c 100644 --- a/format/FormatSER.py +++ b/format/FormatSER.py @@ -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 # @@ -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 = {} @@ -255,7 +248,7 @@ def _read_metadata(image_file): hd["ArraySizeY"] = struct.unpack("