diff --git a/.github/workflows/code-format.yml b/.github/workflows/code-format.yml index 233066c..32623cf 100644 --- a/.github/workflows/code-format.yml +++ b/.github/workflows/code-format.yml @@ -38,19 +38,19 @@ jobs: - name: yapf run: yapf --diff --parallel --recursive . -# imports-check-isort: -# runs-on: ubuntu-20.04 -# steps: -# - uses: actions/checkout@master -# - uses: actions/setup-python@v2 -# with: -# python-version: 3.8 -# - name: Install isort -# run: | -# pip install isort -# pip list -# - name: isort -# run: isort --check-only . + imports-check-isort: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@master + - uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: Install isort + run: | + pip install isort + pip list + - name: isort + run: isort --check-only . #typing-check-mypy: # runs-on: ubuntu-20.04 diff --git a/birl/benchmark.py b/birl/benchmark.py index 85644fb..934b28d 100644 --- a/birl/benchmark.py +++ b/birl/benchmark.py @@ -27,15 +27,23 @@ # this is used while calling this file as a script sys.path += [os.path.abspath('.'), os.path.abspath('..')] # Add path to root -from birl.utilities.data_io import update_path, create_folder, image_sizes, load_landmarks, load_image, save_image -from birl.utilities.dataset import image_histogram_matching, common_landmarks +from birl.utilities.data_io import create_folder, image_sizes, load_image, load_landmarks, save_image, update_path +from birl.utilities.dataset import common_landmarks, image_histogram_matching +from birl.utilities.drawing import draw_image_points, draw_images_warped_landmarks, export_figure, overlap_two_images from birl.utilities.evaluate import ( - compute_target_regist_error_statistic, compute_affine_transf_diff, compute_tre_robustness + compute_affine_transf_diff, + compute_target_regist_error_statistic, + compute_tre_robustness, ) from birl.utilities.experiments import ( - nb_workers, exec_commands, string_dict, iterate_mproc_map, create_basic_parser, parse_arg_params, Experiment + create_basic_parser, + exec_commands, + Experiment, + iterate_mproc_map, + nb_workers, + parse_arg_params, + string_dict, ) -from birl.utilities.drawing import (export_figure, draw_image_points, draw_images_warped_landmarks, overlap_two_images) from birl.utilities.registration import estimate_affine_transform #: In case provided dataset and complete (true) dataset differ diff --git a/birl/bm_template.py b/birl/bm_template.py index e97d63d..ba8cf9e 100644 --- a/birl/bm_template.py +++ b/birl/bm_template.py @@ -26,8 +26,8 @@ # this is used while calling this file as a script sys.path += [os.path.abspath('.'), os.path.abspath('..')] # Add path to root -from birl.utilities.experiments import create_basic_parser from birl.benchmark import ImRegBenchmark +from birl.utilities.experiments import create_basic_parser class BmTemplate(ImRegBenchmark): diff --git a/birl/utilities/data_io.py b/birl/utilities/data_io.py index a1aa4c1..abac48f 100644 --- a/birl/utilities/data_io.py +++ b/birl/utilities/data_io.py @@ -9,14 +9,14 @@ import warnings from functools import wraps -import SimpleITK as sitk import cv2 as cv import nibabel import numpy as np import pandas as pd +import SimpleITK as sitk import yaml from PIL import Image -from skimage.color import rgb2gray, gray2rgb +from skimage.color import gray2rgb, rgb2gray #: landmarks coordinates, loading from CSV file LANDMARK_COORDS = ['X', 'Y'] diff --git a/birl/utilities/dataset.py b/birl/utilities/dataset.py index 693c8ec..38f5b37 100644 --- a/birl/utilities/dataset.py +++ b/birl/utilities/dataset.py @@ -11,21 +11,21 @@ import matplotlib.pyplot as plt import numpy as np -from PIL import Image from cv2 import ( - IMWRITE_JPEG_QUALITY, - IMWRITE_PNG_COMPRESSION, - COLOR_RGBA2RGB, COLOR_RGB2BGR, - INTER_LINEAR, - GaussianBlur, + COLOR_RGBA2RGB, cvtColor, + GaussianBlur, imwrite, + IMWRITE_JPEG_QUALITY, + IMWRITE_PNG_COMPRESSION, + INTER_LINEAR, resize, ) from matplotlib.path import Path -from scipy import spatial, optimize -from skimage.color import rgb2hsv, hsv2rgb, rgb2lab, lab2rgb, lch2lab, lab2lch, rgb2hed, hed2rgb, rgb2luv, luv2rgb +from PIL import Image +from scipy import optimize, spatial +from skimage.color import hed2rgb, hsv2rgb, lab2lch, lab2rgb, lch2lab, luv2rgb, rgb2hed, rgb2hsv, rgb2lab, rgb2luv from skimage.exposure import rescale_intensity from skimage.filters import threshold_otsu diff --git a/birl/utilities/drawing.py b/birl/utilities/drawing.py index b370c36..71d3aba 100644 --- a/birl/utilities/drawing.py +++ b/birl/utilities/drawing.py @@ -10,8 +10,9 @@ import matplotlib.pylab as plt import numpy as np +from matplotlib import colors as plt_colors +from matplotlib import ticker as plt_ticker from PIL import ImageDraw -from matplotlib import colors as plt_colors, ticker as plt_ticker from birl.utilities.data_io import convert_ndarray2image from birl.utilities.dataset import scale_large_images_landmarks diff --git a/bm_ANHIR/evaluate_submission.py b/bm_ANHIR/evaluate_submission.py index 0d5cad7..e303192 100644 --- a/bm_ANHIR/evaluate_submission.py +++ b/bm_ANHIR/evaluate_submission.py @@ -73,10 +73,10 @@ import pandas as pd sys.path += [os.path.abspath('.'), os.path.abspath('..')] # Add path to root +from birl.benchmark import _df_drop_unnamed, COL_PAIRED_LANDMARKS, filter_paired_landmarks, ImRegBenchmark from birl.utilities.data_io import create_folder, load_landmarks, save_landmarks, update_path from birl.utilities.dataset import parse_path_scale -from birl.utilities.experiments import iterate_mproc_map, parse_arg_params, FORMAT_DATE_TIME, nb_workers -from birl.benchmark import COL_PAIRED_LANDMARKS, ImRegBenchmark, filter_paired_landmarks, _df_drop_unnamed +from birl.utilities.experiments import FORMAT_DATE_TIME, iterate_mproc_map, nb_workers, parse_arg_params NB_WORKERS = nb_workers(0.9) NAME_CSV_RESULTS = 'registration-results.csv' diff --git a/bm_ANHIR/generate_regist_pairs.py b/bm_ANHIR/generate_regist_pairs.py index 2d198e9..705d652 100644 --- a/bm_ANHIR/generate_regist_pairs.py +++ b/bm_ANHIR/generate_regist_pairs.py @@ -15,9 +15,9 @@ import tqdm sys.path += [os.path.abspath('.'), os.path.abspath('..')] # Add path to root -from birl.utilities.data_io import image_sizes, update_path -from birl.utilities.dataset import IMAGE_EXTENSIONS, generate_pairing from birl.benchmark import ImRegBenchmark +from birl.utilities.data_io import image_sizes, update_path +from birl.utilities.dataset import generate_pairing, IMAGE_EXTENSIONS DATASET_IMAGES = '/datagrid/Medical/dataset_ANHIR/images_private' DATASET_LANDMARKS = '/datagrid/Medical/dataset_ANHIR/landmarks_all' diff --git a/bm_dataset/convert_tiff2png.py b/bm_dataset/convert_tiff2png.py index fa8086c..ce77b03 100644 --- a/bm_dataset/convert_tiff2png.py +++ b/bm_dataset/convert_tiff2png.py @@ -40,8 +40,8 @@ ) sys.path += [os.path.abspath('.'), os.path.abspath('..')] # Add path to root -from birl.utilities.experiments import iterate_mproc_map, nb_workers from birl.utilities.dataset import args_expand_parse_images +from birl.utilities.experiments import iterate_mproc_map, nb_workers DEFAULT_LEVEL = 1 MAX_LOAD_IMAGE_SIZE = 16000 diff --git a/bm_dataset/create_real_synth_dataset.py b/bm_dataset/create_real_synth_dataset.py index c4ec16b..bbd3b20 100644 --- a/bm_dataset/create_real_synth_dataset.py +++ b/bm_dataset/create_real_synth_dataset.py @@ -27,16 +27,16 @@ print('No display found. Using non-interactive Agg backend') matplotlib.use('Agg') -import tqdm +import matplotlib.pyplot as plt import numpy as np import pandas as pd +import tqdm from PIL import Image -from scipy import ndimage, stats, interpolate -import matplotlib.pyplot as plt +from scipy import interpolate, ndimage, stats sys.path += [os.path.abspath('.'), os.path.abspath('..')] # Add path to root -from birl.utilities.experiments import parse_arg_params, nb_workers from birl.utilities.data_io import LANDMARK_COORDS +from birl.utilities.experiments import nb_workers, parse_arg_params COLUMNS_COORD = LANDMARK_COORDS NB_WORKERS = nb_workers(0.8) diff --git a/bm_dataset/crop_tissue_images.py b/bm_dataset/crop_tissue_images.py index 6436074..a43007c 100644 --- a/bm_dataset/crop_tissue_images.py +++ b/bm_dataset/crop_tissue_images.py @@ -26,9 +26,13 @@ sys.path += [os.path.abspath('.'), os.path.abspath('..')] # Add path to root from birl.utilities.dataset import ( - find_largest_object, project_object_edge, load_large_image, save_large_image, args_expand_parse_images + args_expand_parse_images, + find_largest_object, + load_large_image, + project_object_edge, + save_large_image, ) -from birl.utilities.experiments import iterate_mproc_map, try_decorator, nb_workers +from birl.utilities.experiments import iterate_mproc_map, nb_workers, try_decorator NB_WORKERS = nb_workers(0.5) SCALE_SIZE = 512 diff --git a/bm_dataset/generate_regist_pairs.py b/bm_dataset/generate_regist_pairs.py index 20b0f01..749c8e7 100644 --- a/bm_dataset/generate_regist_pairs.py +++ b/bm_dataset/generate_regist_pairs.py @@ -25,9 +25,9 @@ import pandas as pd sys.path += [os.path.abspath('.'), os.path.abspath('..')] # Add path to root +from birl.benchmark import ImRegBenchmark from birl.utilities.data_io import image_sizes from birl.utilities.experiments import parse_arg_params -from birl.benchmark import ImRegBenchmark # list of combination options OPTIONS_COMBINE = ('first2all', 'each2all') diff --git a/bm_dataset/rescale_tissue_images.py b/bm_dataset/rescale_tissue_images.py index 28cf996..820594b 100644 --- a/bm_dataset/rescale_tissue_images.py +++ b/bm_dataset/rescale_tissue_images.py @@ -26,9 +26,9 @@ import cv2 as cv sys.path += [os.path.abspath('.'), os.path.abspath('..')] # Add path to root -from birl.utilities.experiments import iterate_mproc_map, is_iterable, nb_workers -from birl.utilities.dataset import (load_large_image, save_large_image, parse_path_scale, args_expand_parse_images) from birl.utilities.data_io import create_folder +from birl.utilities.dataset import args_expand_parse_images, load_large_image, parse_path_scale, save_large_image +from birl.utilities.experiments import is_iterable, iterate_mproc_map, nb_workers NB_WORKERS = nb_workers(0.5) DEFAULT_SCALES = (5, 10, 15, 20, 25, 50) diff --git a/bm_dataset/rescale_tissue_landmarks.py b/bm_dataset/rescale_tissue_landmarks.py index 37e98e7..4b1e705 100644 --- a/bm_dataset/rescale_tissue_landmarks.py +++ b/bm_dataset/rescale_tissue_landmarks.py @@ -39,11 +39,11 @@ import pandas as pd sys.path += [os.path.abspath('.'), os.path.abspath('..')] # Add path to root -from birl.utilities.experiments import iterate_mproc_map, parse_arg_params, is_iterable from birl.utilities.data_io import create_folder, load_landmarks_csv, save_landmarks_csv -from birl.utilities.dataset import (list_sub_folders, parse_path_scale, compute_bounding_polygon, inside_polygon) +from birl.utilities.dataset import compute_bounding_polygon, inside_polygon, list_sub_folders, parse_path_scale +from birl.utilities.experiments import is_iterable, iterate_mproc_map, parse_arg_params from birl.utilities.registration import estimate_affine_transform, transform_points -from bm_dataset.rescale_tissue_images import NB_WORKERS, DEFAULT_SCALES, FOLDER_TEMPLATE +from bm_dataset.rescale_tissue_images import DEFAULT_SCALES, FOLDER_TEMPLATE, NB_WORKERS def arg_parse_params(): diff --git a/bm_dataset/split_images_two_tissues.py b/bm_dataset/split_images_two_tissues.py index 61d0284..319f501 100644 --- a/bm_dataset/split_images_two_tissues.py +++ b/bm_dataset/split_images_two_tissues.py @@ -25,7 +25,11 @@ sys.path += [os.path.abspath('.'), os.path.abspath('..')] # Add path to root from birl.utilities.dataset import ( - find_split_objects, project_object_edge, load_large_image, save_large_image, args_expand_parse_images + args_expand_parse_images, + find_split_objects, + load_large_image, + project_object_edge, + save_large_image, ) from birl.utilities.experiments import iterate_mproc_map, nb_workers diff --git a/bm_experiments/bm_ANTs.py b/bm_experiments/bm_ANTs.py index 29fcf5b..3334d58 100644 --- a/bm_experiments/bm_ANTs.py +++ b/bm_experiments/bm_ANTs.py @@ -82,11 +82,15 @@ import pandas as pd sys.path += [os.path.abspath('.'), os.path.abspath('..')] # Add path to root +from birl.benchmark import ImRegBenchmark from birl.utilities.data_io import ( - load_landmarks, save_landmarks, load_config_args, convert_image_to_nifti_gray, convert_image_from_nifti + convert_image_from_nifti, + convert_image_to_nifti_gray, + load_config_args, + load_landmarks, + save_landmarks, ) from birl.utilities.experiments import exec_commands -from birl.benchmark import ImRegBenchmark from bm_experiments import bm_comp_perform diff --git a/bm_experiments/bm_DROP.py b/bm_experiments/bm_DROP.py index 2245448..e0617b5 100644 --- a/bm_experiments/bm_DROP.py +++ b/bm_experiments/bm_DROP.py @@ -64,14 +64,18 @@ import sys import time -import SimpleITK as sitk import numpy as np +import SimpleITK as sitk sys.path += [os.path.abspath('.'), os.path.abspath('..')] # Add path to root +from birl.benchmark import ImRegBenchmark from birl.utilities.data_io import ( - convert_image_to_mhd, convert_image_from_mhd, save_landmarks, load_landmarks, image_sizes + convert_image_from_mhd, + convert_image_to_mhd, + image_sizes, + load_landmarks, + save_landmarks, ) -from birl.benchmark import ImRegBenchmark from bm_experiments import bm_comp_perform diff --git a/bm_experiments/bm_DROP2.py b/bm_experiments/bm_DROP2.py index f2ae9c8..973f108 100644 --- a/bm_experiments/bm_DROP2.py +++ b/bm_experiments/bm_DROP2.py @@ -52,11 +52,11 @@ import shutil import sys -import SimpleITK as sitk import numpy as np +import SimpleITK as sitk sys.path += [os.path.abspath('.'), os.path.abspath('..')] # Add path to root -from birl.utilities.data_io import save_landmarks, load_landmarks, load_config_args +from birl.utilities.data_io import load_config_args, load_landmarks, save_landmarks from bm_experiments import bm_comp_perform from bm_experiments.bm_DROP import BmDROP diff --git a/bm_experiments/bm_RVSS.py b/bm_experiments/bm_RVSS.py index 6b56337..c6969fb 100644 --- a/bm_experiments/bm_RVSS.py +++ b/bm_experiments/bm_RVSS.py @@ -44,9 +44,9 @@ import sys sys.path += [os.path.abspath('.'), os.path.abspath('..')] # Add path to root -from birl.utilities.data_io import load_landmarks, save_landmarks, load_config_yaml -from birl.utilities.experiments import exec_commands, dict_deep_update from birl.benchmark import ImRegBenchmark +from birl.utilities.data_io import load_config_yaml, load_landmarks, save_landmarks +from birl.utilities.experiments import dict_deep_update, exec_commands from bm_experiments import bm_comp_perform from bm_experiments.bm_bUnwarpJ import BmUnwarpJ diff --git a/bm_experiments/bm_bUnwarpJ.py b/bm_experiments/bm_bUnwarpJ.py index b9c64b6..d5acca6 100644 --- a/bm_experiments/bm_bUnwarpJ.py +++ b/bm_experiments/bm_bUnwarpJ.py @@ -55,9 +55,9 @@ import sys sys.path += [os.path.abspath('.'), os.path.abspath('..')] # Add path to root -from birl.utilities.data_io import update_path, load_landmarks, save_landmarks, load_config_yaml -from birl.utilities.experiments import exec_commands, dict_deep_update from birl.benchmark import ImRegBenchmark +from birl.utilities.data_io import load_config_yaml, load_landmarks, save_landmarks, update_path +from birl.utilities.experiments import dict_deep_update, exec_commands from bm_experiments import bm_comp_perform diff --git a/bm_experiments/bm_comp_perform.py b/bm_experiments/bm_comp_perform.py index f41dd1d..aba86af 100644 --- a/bm_experiments/bm_comp_perform.py +++ b/bm_experiments/bm_comp_perform.py @@ -39,13 +39,14 @@ matplotlib.use('Agg') import numpy as np -from skimage import data, io, __version__ as skimage__version -from skimage.transform import resize, warp, AffineTransform +from skimage import __version__ as skimage__version +from skimage import data, io from skimage.color import rgb2gray +from skimage.feature import match_descriptors, ORB from skimage.measure import ransac -from skimage.util import random_noise from skimage.restoration import denoise_bilateral, denoise_wavelet -from skimage.feature import ORB, match_descriptors +from skimage.transform import AffineTransform, resize, warp +from skimage.util import random_noise sys.path += [os.path.abspath('.'), os.path.abspath('..')] # Add path to root from birl.utilities.experiments import computer_info diff --git a/bm_experiments/bm_elastix.py b/bm_experiments/bm_elastix.py index 408cd80..2421c67 100644 --- a/bm_experiments/bm_elastix.py +++ b/bm_experiments/bm_elastix.py @@ -75,9 +75,9 @@ import pandas as pd sys.path += [os.path.abspath('.'), os.path.abspath('..')] # Add path to root +from birl.benchmark import ImRegBenchmark from birl.utilities.data_io import load_landmarks, save_landmarks, save_landmarks_pts from birl.utilities.experiments import exec_commands -from birl.benchmark import ImRegBenchmark from bm_experiments import bm_comp_perform diff --git a/bm_experiments/bm_rNiftyReg.py b/bm_experiments/bm_rNiftyReg.py index ea13974..88fbe13 100644 --- a/bm_experiments/bm_rNiftyReg.py +++ b/bm_experiments/bm_rNiftyReg.py @@ -46,8 +46,8 @@ import sys sys.path += [os.path.abspath('.'), os.path.abspath('..')] # Add path to root -from birl.utilities.data_io import load_landmarks, save_landmarks from birl.benchmark import ImRegBenchmark +from birl.utilities.data_io import load_landmarks, save_landmarks from bm_experiments import bm_comp_perform diff --git a/bm_experiments/evaluate_experiment.py b/bm_experiments/evaluate_experiment.py index 885b371..7d07ef0 100644 --- a/bm_experiments/evaluate_experiment.py +++ b/bm_experiments/evaluate_experiment.py @@ -28,8 +28,8 @@ import pandas as pd sys.path += [os.path.abspath('.'), os.path.abspath('..')] # Add path to root -from birl.utilities.experiments import iterate_mproc_map, parse_arg_params, nb_workers -from birl.benchmark import ImRegBenchmark, export_summary_results +from birl.benchmark import export_summary_results, ImRegBenchmark +from birl.utilities.experiments import iterate_mproc_map, nb_workers, parse_arg_params #: default number of used threads NB_WORKERS = nb_workers(0.75) diff --git a/scripts/Python/run_SimpleElastix.py b/scripts/Python/run_SimpleElastix.py index 2a71198..6961a83 100644 --- a/scripts/Python/run_SimpleElastix.py +++ b/scripts/Python/run_SimpleElastix.py @@ -35,8 +35,8 @@ import os import sys -import SimpleITK as sitk import numpy as np +import SimpleITK as sitk from PIL import Image diff --git a/scripts/Python/run_SimpleITK.py b/scripts/Python/run_SimpleITK.py index ca12bbf..c535886 100644 --- a/scripts/Python/run_SimpleITK.py +++ b/scripts/Python/run_SimpleITK.py @@ -16,8 +16,8 @@ import os import sys -import SimpleITK as sitk import numpy as np +import SimpleITK as sitk from PIL import Image diff --git a/setup.cfg b/setup.cfg index ca5466d..a63eeaf 100644 --- a/setup.cfg +++ b/setup.cfg @@ -6,6 +6,7 @@ requirements-file = requirements.txt #[unittest] #plugins = nose2.plugins.doctests + [flake8] # http://flake8.pycqa.org/en/latest/user/configuration.html exclude = .tox,*.egg,build,temp @@ -18,6 +19,7 @@ ignore = format = pylint max-line-length = 120 + [tool:pytest] addopts = --doctest-modules @@ -31,6 +33,7 @@ log_file_level = DEBUG #log_file_date_format=%Y-%m-%d %H:%M:%S filterwarnings = ignore::FutureWarning + [pydocstyle] convention = pep257 # D104, D107: Ignore missing docstrings in __init__ files and methods. @@ -38,6 +41,7 @@ convention = pep257 add-ignore = D104,D107,D202 max-line-length = 120 + [yapf] based_on_style = pep8 spaces_before_comment = 2 @@ -48,3 +52,16 @@ DEDENT_CLOSING_BRACKETS = true ALLOW_SPLIT_BEFORE_DICT_VALUE = false BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF = true NO_SPACES_AROUND_SELECTED_BINARY_OPERATORS = false + + +[isort] +known_first_party = + birl + bm_experiments + tests + notebooks +line_length = 120 +order_by_type = False +# 3 - Vertical Hanging Indent +multi_line_output = 3 +include_trailing_comma = True diff --git a/tests/test_benchmark.py b/tests/test_benchmark.py index 1bef7a1..41c8ff0 100644 --- a/tests/test_benchmark.py +++ b/tests/test_benchmark.py @@ -19,14 +19,14 @@ import numpy as np import pandas as pd -from numpy.testing import assert_raises, assert_array_almost_equal +from numpy.testing import assert_array_almost_equal, assert_raises sys.path += [os.path.abspath('.'), os.path.abspath('..')] # Add path to root -from birl.utilities.data_io import update_path, save_config_yaml -from birl.utilities.dataset import args_expand_parse_images -from birl.utilities.experiments import parse_arg_params, try_decorator from birl.benchmark import ImRegBenchmark from birl.bm_template import BmTemplate +from birl.utilities.data_io import save_config_yaml, update_path +from birl.utilities.dataset import args_expand_parse_images +from birl.utilities.experiments import parse_arg_params, try_decorator PATH_ROOT = os.path.dirname(update_path('birl')) PATH_DATA = update_path('data-images') diff --git a/tests/test_data-utils.py b/tests/test_data-utils.py index 515ec27..ddcb005 100644 --- a/tests/test_data-utils.py +++ b/tests/test_data-utils.py @@ -12,8 +12,8 @@ from parameterized import parameterized sys.path += [os.path.abspath('.'), os.path.abspath('..')] # Add path to root -from birl.utilities.data_io import update_path, load_image -from birl.utilities.dataset import image_histogram_matching, CONVERT_RGB +from birl.utilities.data_io import load_image, update_path +from birl.utilities.dataset import CONVERT_RGB, image_histogram_matching PATH_ROOT = os.path.dirname(update_path('birl')) PATH_DATA = update_path('data-images')