From d1bbf9aa107559d86864738d63e54791290b5675 Mon Sep 17 00:00:00 2001 From: jolaem Date: Fri, 22 Mar 2024 10:11:25 +0000 Subject: [PATCH 1/2] Fix IO errors with corrupted files. Try and except block was added to inform user with the filename and path of the corrupted file. --- avae/data.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/avae/data.py b/avae/data.py index 993fcc0..9cc868f 100644 --- a/avae/data.py +++ b/avae/data.py @@ -349,8 +349,15 @@ def read(self, filename): return np.load(os.path.join(self.root_dir, filename)) elif self.datatype == "mrc": - with mrcfile.open(os.path.join(self.root_dir, filename)) as f: - return np.array(f.data) + try: + with mrcfile.open(os.path.join(self.root_dir, filename)) as f: + return np.array(f.data) + except IOError: + raise IOError( + "File {} is corrupted.".format( + os.path.join(self.root_dir, filename) + ) + ) def voxel_transformation(self, x): From 1817e6e3f85b7c3d6d8f2aed31c435023bc082d0 Mon Sep 17 00:00:00 2001 From: jolaem Date: Fri, 22 Mar 2024 17:50:24 +0000 Subject: [PATCH 2/2] Correct IOError to ValueError. --- avae/data.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/avae/data.py b/avae/data.py index 9cc868f..1e86e78 100644 --- a/avae/data.py +++ b/avae/data.py @@ -352,8 +352,8 @@ def read(self, filename): try: with mrcfile.open(os.path.join(self.root_dir, filename)) as f: return np.array(f.data) - except IOError: - raise IOError( + except ValueError: + raise ValueError( "File {} is corrupted.".format( os.path.join(self.root_dir, filename) )