From fbbc23219d25c03550be6ea1d27f23785cf169ae Mon Sep 17 00:00:00 2001 From: alex-rakowski Date: Thu, 9 Nov 2023 11:36:48 -0800 Subject: [PATCH] correcting multiple exception handling --- py4DSTEM/braggvectors/diskdetection_aiml_cuda.py | 2 +- py4DSTEM/braggvectors/diskdetection_cuda.py | 2 +- py4DSTEM/datacube/virtualimage.py | 2 +- py4DSTEM/io/legacy/read_utils.py | 2 +- py4DSTEM/process/utils/multicorr.py | 2 +- py4DSTEM/utils/configuration_checker.py | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/py4DSTEM/braggvectors/diskdetection_aiml_cuda.py b/py4DSTEM/braggvectors/diskdetection_aiml_cuda.py index bbe0d37d4..7b3687f56 100644 --- a/py4DSTEM/braggvectors/diskdetection_aiml_cuda.py +++ b/py4DSTEM/braggvectors/diskdetection_aiml_cuda.py @@ -638,7 +638,7 @@ def upsampled_correlation_cp(imageCorr, upsampleFactor, xyShift): dx = (icc[2, 1] - icc[0, 1]) / (4 * icc[1, 1] - 2 * icc[2, 1] - 2 * icc[0, 1]) dy = (icc[1, 2] - icc[1, 0]) / (4 * icc[1, 1] - 2 * icc[1, 2] - 2 * icc[1, 0]) # TODO I think this is just the Index Error - except IndexError or Exception: + except (IndexError, Exception): dx, dy = ( 0, 0, diff --git a/py4DSTEM/braggvectors/diskdetection_cuda.py b/py4DSTEM/braggvectors/diskdetection_cuda.py index 55e782028..2c44a63a8 100644 --- a/py4DSTEM/braggvectors/diskdetection_cuda.py +++ b/py4DSTEM/braggvectors/diskdetection_cuda.py @@ -619,7 +619,7 @@ def upsampled_correlation(imageCorr, upsampleFactor, xyShift): 4 * icc[1, 1] - 2 * icc[1, 2] - 2 * icc[1, 0] ) # TODO Work out what exception to use - except IndexError or Exception: + except (IndexError, Exception): dx, dy = ( 0, 0, diff --git a/py4DSTEM/datacube/virtualimage.py b/py4DSTEM/datacube/virtualimage.py index 51415e9fb..f930b6697 100644 --- a/py4DSTEM/datacube/virtualimage.py +++ b/py4DSTEM/datacube/virtualimage.py @@ -415,7 +415,7 @@ def position_detector( image = self.tree(k) break # TODO check what error is produced when passing nonexistant key to tree - except KeyError or AttributeError: + except (KeyError, AttributeError): pass if image is None: image = self[0, 0] diff --git a/py4DSTEM/io/legacy/read_utils.py b/py4DSTEM/io/legacy/read_utils.py index 27ee5cb7a..a08e7b61d 100644 --- a/py4DSTEM/io/legacy/read_utils.py +++ b/py4DSTEM/io/legacy/read_utils.py @@ -101,7 +101,7 @@ def get_N_dataobjects(filepath, topgroup="4DSTEM_experiment"): try: N_coords = len(f[topgroup]["data/coordinates"].keys()) # TODO work out what exception will be raised - except ValueError or AttributeError or Exception: + except (ValueError, AttributeError, Exception): N_coords = 0 N_do = N_dc + N_cdc + N_ds + N_rs + N_pl + N_pla + N_coords return N_dc, N_cdc, N_ds, N_rs, N_pl, N_pla, N_coords, N_do diff --git a/py4DSTEM/process/utils/multicorr.py b/py4DSTEM/process/utils/multicorr.py index 6760407a6..70b11ad5c 100644 --- a/py4DSTEM/process/utils/multicorr.py +++ b/py4DSTEM/process/utils/multicorr.py @@ -100,7 +100,7 @@ def upsampled_correlation(imageCorr, upsampleFactor, xyShift, device="cpu"): dx = (icc[2, 1] - icc[0, 1]) / (4 * icc[1, 1] - 2 * icc[2, 1] - 2 * icc[0, 1]) dy = (icc[1, 2] - icc[1, 0]) / (4 * icc[1, 1] - 2 * icc[1, 2] - 2 * icc[1, 0]) # TODO work out what error is raised - except IndexError or Exception: + except (IndexError, Exception): dx, dy = ( 0, 0, diff --git a/py4DSTEM/utils/configuration_checker.py b/py4DSTEM/utils/configuration_checker.py index c1bb98c47..df6f037df 100644 --- a/py4DSTEM/utils/configuration_checker.py +++ b/py4DSTEM/utils/configuration_checker.py @@ -392,7 +392,7 @@ def check_cupy_gpu(gratuitously_verbose: bool, **kwargs): d = cp.cuda.Device(i) hasattr(d, "attributes") # TODO work out what error is raised - except AttributeError or Exception: + except (AttributeError, Exception): num_gpus_detected = i break