From f3f5ffa1e7c560312151f6262a2f5c204bcf9362 Mon Sep 17 00:00:00 2001
From: Amir MOHAMMADI <amir.mohammadi@idiap.ch>
Date: Mon, 2 May 2022 18:51:30 +0200
Subject: [PATCH] Flake8 F errors and several bug fixes

---
 bob/bio/vein/algorithm/MiuraMatch.py             |  4 +++-
 bob/bio/vein/config/maximum_curvature.py         |  2 +-
 bob/bio/vein/config/principal_curvature.py       |  2 +-
 bob/bio/vein/config/repeated_line_tracking.py    |  2 +-
 bob/bio/vein/config/wide_line_detector.py        |  2 +-
 bob/bio/vein/database/fv3d.py                    |  1 -
 bob/bio/vein/database/verafinger.py              |  1 -
 bob/bio/vein/extractor/MaximumCurvature.py       |  2 --
 .../vein/extractor/NormalisedCrossCorrelation.py |  2 --
 bob/bio/vein/extractor/PrincipalCurvature.py     |  2 --
 bob/bio/vein/extractor/__init__.py               | 10 +++++-----
 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/preprocessor.py        |  3 +--
 bob/bio/vein/script/blame.py                     |  2 +-
 bob/bio/vein/script/compare_rois.py              |  1 +
 bob/bio/vein/script/validate.py                  |  2 --
 bob/bio/vein/script/view_sample.py               |  9 +++------
 bob/bio/vein/tests/test_tools.py                 | 16 ++++++++--------
 doc/conf.py                                      |  2 --
 matlab/compare.py                                |  2 --
 22 files changed, 26 insertions(+), 47 deletions(-)

diff --git a/bob/bio/vein/algorithm/MiuraMatch.py b/bob/bio/vein/algorithm/MiuraMatch.py
index 4633425..774c8f2 100644
--- a/bob/bio/vein/algorithm/MiuraMatch.py
+++ b/bob/bio/vein/algorithm/MiuraMatch.py
@@ -103,7 +103,9 @@ 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(image_, 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
diff --git a/bob/bio/vein/config/maximum_curvature.py b/bob/bio/vein/config/maximum_curvature.py
index 32f816d..3935bec 100644
--- a/bob/bio/vein/config/maximum_curvature.py
+++ b/bob/bio/vein/config/maximum_curvature.py
@@ -17,7 +17,7 @@ import tempfile
 
 from sklearn.pipeline import make_pipeline
 
-from bob.bio.base.pipelines import BioAlgorithmLegacy, PipelineSimple
+from bob.bio.base.pipelines import PipelineSimple
 from bob.bio.base.transformers import (
     ExtractorTransformer,
     PreprocessorTransformer,
diff --git a/bob/bio/vein/config/principal_curvature.py b/bob/bio/vein/config/principal_curvature.py
index 47cbe72..e761cd6 100644
--- a/bob/bio/vein/config/principal_curvature.py
+++ b/bob/bio/vein/config/principal_curvature.py
@@ -76,7 +76,7 @@ else:
     legacy_temp_dir = tempfile.TemporaryDirectory().name
 
 
-from bob.bio.base.pipelines import BioAlgorithmLegacy, PipelineSimple
+from bob.bio.base.pipelines import PipelineSimple
 
 biometric_algorithm = MiuraMatch(ch=18, cw=28)
 
diff --git a/bob/bio/vein/config/repeated_line_tracking.py b/bob/bio/vein/config/repeated_line_tracking.py
index 7407bd4..b5853ea 100644
--- a/bob/bio/vein/config/repeated_line_tracking.py
+++ b/bob/bio/vein/config/repeated_line_tracking.py
@@ -16,7 +16,7 @@ import tempfile
 
 from sklearn.pipeline import make_pipeline
 
-from bob.bio.base.pipelines import BioAlgorithmLegacy, PipelineSimple
+from bob.bio.base.pipelines import PipelineSimple
 from bob.bio.base.transformers import (
     ExtractorTransformer,
     PreprocessorTransformer,
diff --git a/bob/bio/vein/config/wide_line_detector.py b/bob/bio/vein/config/wide_line_detector.py
index d88d505..5c3be3a 100644
--- a/bob/bio/vein/config/wide_line_detector.py
+++ b/bob/bio/vein/config/wide_line_detector.py
@@ -16,7 +16,7 @@ import tempfile
 
 from sklearn.pipeline import make_pipeline
 
-from bob.bio.base.pipelines import BioAlgorithmLegacy, PipelineSimple
+from bob.bio.base.pipelines import PipelineSimple
 from bob.bio.base.transformers import (
     ExtractorTransformer,
     PreprocessorTransformer,
diff --git a/bob/bio/vein/database/fv3d.py b/bob/bio/vein/database/fv3d.py
index b51d477..7c60331 100644
--- a/bob/bio/vein/database/fv3d.py
+++ b/bob/bio/vein/database/fv3d.py
@@ -7,7 +7,6 @@ import numpy
 
 from bob.bio.base.database import BioDatabase, BioFile
 
-from ..preprocessor.utils import poly_to_mask
 from . import AnnotatedArray
 
 
diff --git a/bob/bio/vein/database/verafinger.py b/bob/bio/vein/database/verafinger.py
index ea3db17..397bb4a 100644
--- a/bob/bio/vein/database/verafinger.py
+++ b/bob/bio/vein/database/verafinger.py
@@ -6,7 +6,6 @@ import os
 
 from bob.bio.base.database import BioDatabase, BioFile
 
-from ..preprocessor.utils import poly_to_mask
 from . import AnnotatedArray
 
 
diff --git a/bob/bio/vein/extractor/MaximumCurvature.py b/bob/bio/vein/extractor/MaximumCurvature.py
index 5248d97..518d562 100644
--- a/bob/bio/vein/extractor/MaximumCurvature.py
+++ b/bob/bio/vein/extractor/MaximumCurvature.py
@@ -6,8 +6,6 @@ import math
 import numpy
 import scipy.ndimage
 
-import bob.io.base
-
 from bob.bio.base.extractor import Extractor
 
 
diff --git a/bob/bio/vein/extractor/NormalisedCrossCorrelation.py b/bob/bio/vein/extractor/NormalisedCrossCorrelation.py
index df44560..b1a73e4 100644
--- a/bob/bio/vein/extractor/NormalisedCrossCorrelation.py
+++ b/bob/bio/vein/extractor/NormalisedCrossCorrelation.py
@@ -3,8 +3,6 @@
 
 import numpy
 
-import bob.io.base
-
 from bob.bio.base.extractor import Extractor
 
 
diff --git a/bob/bio/vein/extractor/PrincipalCurvature.py b/bob/bio/vein/extractor/PrincipalCurvature.py
index 84c1bbe..45297ec 100644
--- a/bob/bio/vein/extractor/PrincipalCurvature.py
+++ b/bob/bio/vein/extractor/PrincipalCurvature.py
@@ -5,8 +5,6 @@ import numpy
 
 from scipy.ndimage import gaussian_filter
 
-import bob.io.base
-
 from bob.bio.base.extractor import Extractor
 
 
diff --git a/bob/bio/vein/extractor/__init__.py b/bob/bio/vein/extractor/__init__.py
index 4f5cbfb..e50ec98 100644
--- a/bob/bio/vein/extractor/__init__.py
+++ b/bob/bio/vein/extractor/__init__.py
@@ -1,9 +1,9 @@
 # isort: skip_file
-from .NormalisedCrossCorrelation import NormalisedCrossCorrelation
-from .PrincipalCurvature import PrincipalCurvature
-from .RepeatedLineTracking import RepeatedLineTracking
-from .WideLineDetector import WideLineDetector
-from .MaximumCurvature import MaximumCurvature
+from .NormalisedCrossCorrelation import NormalisedCrossCorrelation  # noqa: F401
+from .PrincipalCurvature import PrincipalCurvature  # noqa: F401
+from .RepeatedLineTracking import RepeatedLineTracking  # noqa: F401
+from .WideLineDetector import WideLineDetector  # noqa: F401
+from .MaximumCurvature import MaximumCurvature  # noqa: F401
 
 # gets sphinx autodoc done right - don't remove it
 __all__ = [_ for _ in dir() if not _.startswith("_")]
diff --git a/bob/bio/vein/preprocessor/crop.py b/bob/bio/vein/preprocessor/crop.py
index 4ca5b2d..d8bffde 100644
--- a/bob/bio/vein/preprocessor/crop.py
+++ b/bob/bio/vein/preprocessor/crop.py
@@ -4,8 +4,6 @@
 
 """Base utilities for pre-cropping images"""
 
-import numpy
-
 
 class Cropper(object):
     """This is the base class for all croppers
diff --git a/bob/bio/vein/preprocessor/filters.py b/bob/bio/vein/preprocessor/filters.py
index 9ef0a9c..6714c4c 100644
--- a/bob/bio/vein/preprocessor/filters.py
+++ b/bob/bio/vein/preprocessor/filters.py
@@ -3,8 +3,6 @@
 
 """Base utilities for post-filtering vein images"""
 
-import numpy
-
 
 class Filter(object):
     """Objects of this class filter the input image"""
diff --git a/bob/bio/vein/preprocessor/mask.py b/bob/bio/vein/preprocessor/mask.py
index 01dd15d..3e146fb 100644
--- a/bob/bio/vein/preprocessor/mask.py
+++ b/bob/bio/vein/preprocessor/mask.py
@@ -7,8 +7,6 @@ import math
 
 import numpy
 import scipy.ndimage
-import skimage.filters
-import skimage.morphology
 
 from .utils import poly_to_mask
 
diff --git a/bob/bio/vein/preprocessor/preprocessor.py b/bob/bio/vein/preprocessor/preprocessor.py
index c172f13..5d7fb5f 100644
--- a/bob/bio/vein/preprocessor/preprocessor.py
+++ b/bob/bio/vein/preprocessor/preprocessor.py
@@ -1,7 +1,6 @@
 #!/usr/bin/env python
 # vim: set fileencoding=utf-8 :
-
-import bob.io.base
+import h5py
 
 from bob.bio.base.preprocessor import Preprocessor as BasePreprocessor
 
diff --git a/bob/bio/vein/script/blame.py b/bob/bio/vein/script/blame.py
index 2423684..eb2cfde 100644
--- a/bob/bio/vein/script/blame.py
+++ b/bob/bio/vein/script/blame.py
@@ -73,7 +73,7 @@ def main(user_input=None):
     cases = int(args["--cases"])
 
     # generates a huge
-    from bob.bio.base.score.load import get_negatives_positives, load_score
+    from bob.bio.base.score.load import load_score
 
     scores = []
     names = {}
diff --git a/bob/bio/vein/script/compare_rois.py b/bob/bio/vein/script/compare_rois.py
index 9f94384..7eb7981 100644
--- a/bob/bio/vein/script/compare_rois.py
+++ b/bob/bio/vein/script/compare_rois.py
@@ -48,6 +48,7 @@ import operator
 import os
 import sys
 
+import h5py
 import numpy
 
 import bob.extension.log
diff --git a/bob/bio/vein/script/validate.py b/bob/bio/vein/script/validate.py
index aa46ac7..b338959 100644
--- a/bob/bio/vein/script/validate.py
+++ b/bob/bio/vein/script/validate.py
@@ -172,8 +172,6 @@ def open_multipage_pdf_file(s):
       schema.SchemaError: if the path exists
 
     """
-    import matplotlib.pyplot as mpl
-
     from matplotlib.backends.backend_pdf import PdfPages
 
     return PdfPages(s)
diff --git a/bob/bio/vein/script/view_sample.py b/bob/bio/vein/script/view_sample.py
index 4c7dd42..16a2daf 100644
--- a/bob/bio/vein/script/view_sample.py
+++ b/bob/bio/vein/script/view_sample.py
@@ -47,6 +47,7 @@ import os
 import sys
 
 import docopt
+import h5py
 import numpy
 import schema
 
@@ -88,8 +89,6 @@ def save_figures(title, image, mask, image_pp, binary):
     bob.io.base.save(image, os.path.join(title, "original.png"))
 
     # add preprocessed image
-    from ..preprocessor import utils
-
     img = utils.draw_mask_over_image(image_pp, mask)
     img = numpy.array(img).transpose(2, 0, 1)
     bob.io.base.save(img[:3], os.path.join(title, "preprocessed.png"))
@@ -140,8 +139,6 @@ def proof_figure(title, image, mask, image_pp, binary=None):
     mpl.imshow(image, cmap="gray")
 
     # add preprocessed image
-    from ..preprocessor import utils
-
     img = utils.draw_mask_over_image(image_pp, mask)
     mpl.subplot(images, 1, 2)
     mpl.title("Preprocessed")
@@ -223,7 +220,7 @@ def main(user_input=None):
     try:
         from .validate import setup_logger
 
-        logger = setup_logger("bob.bio.vein", args["--verbose"])
+        setup_logger("bob.bio.vein", args["--verbose"])
         args = validate(args)
     except schema.SchemaError as e:
         sys.exit(e)
@@ -258,7 +255,7 @@ def main(user_input=None):
             binary = numpy.rot90(binary, k=1)
         except Exception:
             binary = None
-        fig = proof_figure(stem, image, mask, image_pp, binary)
+        proof_figure(stem, image, mask, image_pp, binary)
         if args["--save"]:
             save_figures(args["--save"], image, mask, image_pp, binary)
         else:
diff --git a/bob/bio/vein/tests/test_tools.py b/bob/bio/vein/tests/test_tools.py
index 01abd10..0f0570c 100644
--- a/bob/bio/vein/tests/test_tools.py
+++ b/bob/bio/vein/tests/test_tools.py
@@ -248,7 +248,7 @@ def test_max_curvature_HE():
     from ..extractor.MaximumCurvature import MaximumCurvature
 
     MC = MaximumCurvature(sigma=5)
-    extr_data = MC(preproc_data)
+    MC(preproc_data)
     # preprocessor_utils.show_image((255.*extr_data).astype('uint8'))
 
 
@@ -317,7 +317,7 @@ def test_repeated_line_tracking_HE():
         profile_w=PROFILE_WIDTH,
         seed=0,
     )
-    extr_data = RLT(preproc_data)
+    RLT(preproc_data)
 
 
 def test_wide_line_detector():
@@ -384,7 +384,7 @@ def test_wide_line_detector_HE():
         g=SUM_NEIGHBOURHOOD,
         rescale=RESCALE,
     )
-    extr_data = WLD(preproc_data)
+    WLD(preproc_data)
 
 
 def test_miura_match():
@@ -416,16 +416,16 @@ def test_correlate():
 
     template_filename = F(("algorithms", "0001_2_1_120509-135338.mat.hdf5"))
     probe_gen_filename = F(("algorithms", "0001_2_2_120509-135558.mat.hdf5"))
-    probe_imp_filename = F(("algorithms", "0003_2_1_120509-141255.mat.hdf5"))
+    # probe_imp_filename = F(("algorithms", "0003_2_1_120509-141255.mat.hdf5"))
 
     template_vein = bob.io.base.load(template_filename)
     probe_gen_vein = bob.io.base.load(probe_gen_filename)
-    probe_imp_vein = bob.io.base.load(probe_imp_filename)
+    # probe_imp_vein = bob.io.base.load(probe_imp_filename)
 
     from ..algorithm.Correlate import Correlate
 
     C = Correlate()
-    score_gen = C.score(template_vein, probe_gen_vein)
+    C.score(template_vein, probe_gen_vein)
 
     # we don't check here - no templates
 
@@ -545,14 +545,14 @@ def test_mask_to_image():
     def _check_float(n):
         conv = preprocessor_utils.mask_to_image(sample, "float%d" % n)
         nose.tools.eq_(conv.dtype, getattr(numpy, "float%d" % n))
-        assert numpy.array_equal(conv, [0, 1.0]), "%r != %r" % (conv, target)
+        assert numpy.array_equal(conv, [0, 1.0]), "%r != %r" % (conv, [0, 1.0])
 
     _check_float(32)
     _check_float(64)
 
     # This should be unsupported
     try:
-        conv = preprocessor_utils.mask_to_image(sample, "int16")
+        preprocessor_utils.mask_to_image(sample, "int16")
     except TypeError as e:
         assert "int16" in str(e)
     else:
diff --git a/doc/conf.py b/doc/conf.py
index 8673212..755aff1 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -1,9 +1,7 @@
 #!/usr/bin/env python
 # vim: set fileencoding=utf-8 :
 
-import glob
 import os
-import sys
 
 import pkg_resources
 
diff --git a/matlab/compare.py b/matlab/compare.py
index 3abc531..ee378c9 100644
--- a/matlab/compare.py
+++ b/matlab/compare.py
@@ -29,8 +29,6 @@ G_matlab = bob.io.base.load("mc_g_matlab.hdf5")
 G_matlab = G_matlab.T
 
 # Apply Python implementation
-from bob.bio.vein.extractor.MaximumCurvature import MaximumCurvature
-
 MC = MaximumCurvature(3)
 
 kappa = MC.detect_valleys(image, region)  # OK
-- 
GitLab