From 2f4e053dd23b173620f522a1565aba4f6fc3dbb1 Mon Sep 17 00:00:00 2001 From: Amir MOHAMMADI <amir.mohammadi@idiap.ch> Date: Mon, 2 May 2022 18:43:47 +0200 Subject: [PATCH] Fix E and W flake8 errors --- bob/bio/vein/algorithm/Correlate.py | 4 ++-- bob/bio/vein/algorithm/MiuraMatch.py | 6 +++--- bob/bio/vein/extractor/MaximumCurvature.py | 6 +++--- bob/bio/vein/extractor/PrincipalCurvature.py | 4 ++-- bob/bio/vein/extractor/RepeatedLineTracking.py | 17 ++++++++--------- bob/bio/vein/extractor/WideLineDetector.py | 4 ++-- bob/bio/vein/preprocessor/crop.py | 2 +- bob/bio/vein/preprocessor/filters.py | 2 +- bob/bio/vein/preprocessor/mask.py | 2 +- bob/bio/vein/preprocessor/normalize.py | 2 +- bob/bio/vein/preprocessor/utils.py | 2 +- bob/bio/vein/script/view_sample.py | 2 +- bob/bio/vein/tests/test_databases.py | 2 +- 13 files changed, 27 insertions(+), 28 deletions(-) diff --git a/bob/bio/vein/algorithm/Correlate.py b/bob/bio/vein/algorithm/Correlate.py index 4e82f02..e353106 100644 --- a/bob/bio/vein/algorithm/Correlate.py +++ b/bob/bio/vein/algorithm/Correlate.py @@ -47,7 +47,7 @@ class Correlate(Algorithm): """ - I = probe.astype(numpy.float64) + image_ = probe.astype(numpy.float64) if len(model.shape) == 2: model = numpy.array([model]) @@ -58,7 +58,7 @@ class Correlate(Algorithm): for md in model: R = md.astype(numpy.float64) - Nm = skimage.feature.match_template(I, R) + Nm = skimage.feature.match_template(image_, R) # figures out where the maximum is on the resulting matrix t0, s0 = numpy.unravel_index(Nm.argmax(), Nm.shape) diff --git a/bob/bio/vein/algorithm/MiuraMatch.py b/bob/bio/vein/algorithm/MiuraMatch.py index a70a93f..4633425 100644 --- a/bob/bio/vein/algorithm/MiuraMatch.py +++ b/bob/bio/vein/algorithm/MiuraMatch.py @@ -83,7 +83,7 @@ class MiuraMatch(BioAlgorithm): """ - I = probe.astype(numpy.float64) + image_ = probe.astype(numpy.float64) if len(model.shape) == 2: model = numpy.array([model]) @@ -103,7 +103,7 @@ class MiuraMatch(BioAlgorithm): # yields best results. Otherwise, you may try the other options bellow # -> check our test_correlation() method on the test units for more # details and benchmarks. - Nm = scipy.signal.fftconvolve(I, numpy.rot90(crop_R, k=2), "valid") + Nm = scipy.signal.fftconvolve(image_, numpy.rot90(crop_R, k=2), "valid") # 2nd best: use convolve2d or correlate2d directly; # Nm = scipy.signal.convolve2d(I, numpy.rot90(crop_R, k=2), 'valid') # 3rd best: use correlate2d @@ -122,7 +122,7 @@ class MiuraMatch(BioAlgorithm): Nmm / ( crop_R.sum() - + I[ + + image_[ t0 : t0 + h - 2 * self.ch, s0 : s0 + w - 2 * self.cw ].sum() ) diff --git a/bob/bio/vein/extractor/MaximumCurvature.py b/bob/bio/vein/extractor/MaximumCurvature.py index 698ff1b..5248d97 100644 --- a/bob/bio/vein/extractor/MaximumCurvature.py +++ b/bob/bio/vein/extractor/MaximumCurvature.py @@ -33,7 +33,7 @@ class MaximumCurvature(Extractor): self.sigma = sigma def detect_valleys(self, image, mask): - """Detects valleys on the image respecting the mask + r"""Detects valleys on the image respecting the mask This step corresponds to Step 1-1 in the original paper. The objective is, for all 4 cross-sections (z) of the image (horizontal, vertical, 45 and -45 @@ -178,7 +178,7 @@ class MaximumCurvature(Extractor): ) def eval_vein_probabilities(self, k): - """Evaluates joint vein centre probabilities from cross-sections + r"""Evaluates joint vein centre probabilities from cross-sections This function will take $\kappa$ and will calculate the vein centre probabilities taking into consideration valley widths and depths. It @@ -318,7 +318,7 @@ class MaximumCurvature(Extractor): return V def connect_centres(self, V): - """Connects vein centres by filtering vein probabilities ``V`` + r"""Connects vein centres by filtering vein probabilities ``V`` This function does the equivalent of Step 2 / Equation 4 at Miura's paper. diff --git a/bob/bio/vein/extractor/PrincipalCurvature.py b/bob/bio/vein/extractor/PrincipalCurvature.py index 751be99..84c1bbe 100644 --- a/bob/bio/vein/extractor/PrincipalCurvature.py +++ b/bob/bio/vein/extractor/PrincipalCurvature.py @@ -46,14 +46,14 @@ class PrincipalCurvature(Extractor): fingervein image""" finger_mask = numpy.zeros(mask.shape) - finger_mask[mask == True] = 1 + finger_mask[mask == True] = 1 # noqa: E712 sigma = numpy.sqrt(self.sigma**2 / 2) gx = self.ut_gauss(image, self.sigma, 1, 0) gy = self.ut_gauss(image, self.sigma, 0, 1) - Gmag = numpy.sqrt(gx**2 + gy**2) # Gradient magnitude + Gmag = numpy.sqrt(gx**2 + gy**2) # Gradient magnitude # Apply threshold gamma = (self.threshold / 100) * numpy.max(Gmag) diff --git a/bob/bio/vein/extractor/RepeatedLineTracking.py b/bob/bio/vein/extractor/RepeatedLineTracking.py index 65d627c..6a9ec79 100644 --- a/bob/bio/vein/extractor/RepeatedLineTracking.py +++ b/bob/bio/vein/extractor/RepeatedLineTracking.py @@ -54,10 +54,10 @@ class RepeatedLineTracking(Extractor): numpy.random.seed(self.seed) finger_mask = numpy.zeros(mask.shape) - finger_mask[mask == True] = 1 + finger_mask[mask == True] = 1 # noqa: E712 # Rescale image if required - if self.rescale == True: + if self.rescale: scaling_factor = 0.6 # finger_image = bob.ip.base.scale(finger_image, scaling_factor) # finger_mask = bob.ip.base.scale(finger_mask, scaling_factor) @@ -121,14 +121,14 @@ class RepeatedLineTracking(Extractor): finger_mask[:, 0:border] = 0 finger_mask[:, finger_mask.shape[1] - border :] = 0 - ## Uniformly distributed starting points - aux = numpy.argwhere((finger_mask > 0) == True) + # Uniformly distributed starting points + aux = numpy.argwhere(finger_mask > 0) indices = numpy.random.permutation(aux) indices = indices[ 0 : self.iterations, : ] # Limit to number of iterations - ## Iterate through all starting points + # Iterate through all starting points for it in range(0, self.iterations): yc = indices[it, 0] # Current tracking point, y xc = indices[it, 1] # Current tracking point, x @@ -175,7 +175,6 @@ class RepeatedLineTracking(Extractor): bool ) ).T.reshape(-1) - == True ) Nc = numpy.concatenate( (xc + filtermask[tmp, 0], yc + filtermask[tmp, 1]), axis=1 @@ -184,10 +183,10 @@ class RepeatedLineTracking(Extractor): Vl = -1 continue - ## Detect dark line direction near current tracking point + # Detect dark line direction near current tracking point Vdepths = numpy.zeros((Nc.shape[0], 1)) # Valley depths for i in range(0, Nc.shape[0]): - ## Horizontal or vertical + # Horizontal or vertical if Nc[i, 1] == yc: # Horizontal plane yp = Nc[i, 1] @@ -217,7 +216,7 @@ class RepeatedLineTracking(Extractor): + finger_image[int(yp), int(xp - hW)] ) - ## Oblique directions + # Oblique directions if ((Nc[i, 0] > xc) and (Nc[i, 1] < yc)) or ( (Nc[i, 0] < xc) and (Nc[i, 1] > yc) ): diff --git a/bob/bio/vein/extractor/WideLineDetector.py b/bob/bio/vein/extractor/WideLineDetector.py index 9350e72..d64899f 100644 --- a/bob/bio/vein/extractor/WideLineDetector.py +++ b/bob/bio/vein/extractor/WideLineDetector.py @@ -45,10 +45,10 @@ class WideLineDetector(Extractor): finger_image = finger_image.astype(numpy.float64) finger_mask = numpy.zeros(mask.shape) - finger_mask[mask == True] = 1 + finger_mask[mask == True] = 1 # noqa: E712 # Rescale image if required - if self.rescale == True: + if self.rescale: scaling_factor = 0.24 new_size = tuple( diff --git a/bob/bio/vein/preprocessor/crop.py b/bob/bio/vein/preprocessor/crop.py index 7064ff0..4ca5b2d 100644 --- a/bob/bio/vein/preprocessor/crop.py +++ b/bob/bio/vein/preprocessor/crop.py @@ -35,7 +35,7 @@ class Cropper(object): """ - raise NotImplemented("You must implement the __call__ slot") + raise NotImplementedError("You must implement the __call__ slot") class FixedCrop(Cropper): diff --git a/bob/bio/vein/preprocessor/filters.py b/bob/bio/vein/preprocessor/filters.py index 31f3ef1..9ef0a9c 100644 --- a/bob/bio/vein/preprocessor/filters.py +++ b/bob/bio/vein/preprocessor/filters.py @@ -31,7 +31,7 @@ class Filter(object): """ - raise NotImplemented("You must implement the __call__ slot") + raise NotImplementedError("You must implement the __call__ slot") class NoFilter(Filter): diff --git a/bob/bio/vein/preprocessor/mask.py b/bob/bio/vein/preprocessor/mask.py index 7e1551d..01dd15d 100644 --- a/bob/bio/vein/preprocessor/mask.py +++ b/bob/bio/vein/preprocessor/mask.py @@ -91,7 +91,7 @@ class Masker(object): """ - raise NotImplemented("You must implement the __call__ slot") + raise NotImplementedError("You must implement the __call__ slot") class FixedMask(Masker): diff --git a/bob/bio/vein/preprocessor/normalize.py b/bob/bio/vein/preprocessor/normalize.py index f047c1f..7c4f38e 100644 --- a/bob/bio/vein/preprocessor/normalize.py +++ b/bob/bio/vein/preprocessor/normalize.py @@ -38,7 +38,7 @@ class Normalizer(object): """ - raise NotImplemented("You must implement the __call__ slot") + raise NotImplementedError("You must implement the __call__ slot") class NoNormalization(Normalizer): diff --git a/bob/bio/vein/preprocessor/utils.py b/bob/bio/vein/preprocessor/utils.py index b4de161..81931d2 100644 --- a/bob/bio/vein/preprocessor/utils.py +++ b/bob/bio/vein/preprocessor/utils.py @@ -235,7 +235,7 @@ def show_mask_over_image(image, mask, color="red"): def jaccard_index(a, b): - """Calculates the intersection over union for two masks + r"""Calculates the intersection over union for two masks This function calculates the Jaccard index: diff --git a/bob/bio/vein/script/view_sample.py b/bob/bio/vein/script/view_sample.py index 4dccc88..4c7dd42 100644 --- a/bob/bio/vein/script/view_sample.py +++ b/bob/bio/vein/script/view_sample.py @@ -256,7 +256,7 @@ def main(user_input=None): try: binary = f.load(os.path.join(args["<processed>"], "extracted")) binary = numpy.rot90(binary, k=1) - except: + except Exception: binary = None fig = proof_figure(stem, image, mask, image_pp, binary) if args["--save"]: diff --git a/bob/bio/vein/tests/test_databases.py b/bob/bio/vein/tests/test_databases.py index d06a2fb..2e4cf9f 100644 --- a/bob/bio/vein/tests/test_databases.py +++ b/bob/bio/vein/tests/test_databases.py @@ -96,7 +96,7 @@ def test_utfvp(): except Exception: pass - N_SUBJECTS, N_FINGERS, N_SESSIONS = 60, 6, 4 + N_SUBJECTS, N_SESSIONS = 60, 4 # nom nom_parameters = { "N_train": 10, -- GitLab