diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 7e34aba9c..9581303e3 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -30,7 +30,7 @@ jobs: sudo apt update sudo apt-get install -y libopenslide-dev openslide-tools libopenjp2-7 libopenjp2-tools python -m pip install --upgrade pip - python -m pip install ruff==0.5.1 pytest pytest-cov pytest-runner + python -m pip install ruff==0.5.2 pytest pytest-cov pytest-runner pip install -r requirements/requirements.txt - name: Cache tiatoolbox static assets uses: actions/cache@v3 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 987c1c7b0..02b44aa70 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -60,7 +60,7 @@ repos: - id: rst-inline-touching-normal # Detect mistake of inline code touching normal text in rst. - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.5.1 + rev: v0.5.2 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/requirements/requirements_dev.txt b/requirements/requirements_dev.txt index 72ef05024..264af30d1 100644 --- a/requirements/requirements_dev.txt +++ b/requirements/requirements_dev.txt @@ -11,7 +11,7 @@ pytest>=7.2.0 pytest-cov>=4.0.0 pytest-runner>=6.0 pytest-xdist[psutil] -ruff==0.5.1 # This will be updated by pre-commit bot to latest version +ruff==0.5.2 # This will be updated by pre-commit bot to latest version toml>=0.10.2 twine>=4.0.1 wheel>=0.37.1 diff --git a/tiatoolbox/tools/registration/wsi_registration.py b/tiatoolbox/tools/registration/wsi_registration.py index 097cf2e8f..bdfef61b3 100644 --- a/tiatoolbox/tools/registration/wsi_registration.py +++ b/tiatoolbox/tools/registration/wsi_registration.py @@ -332,7 +332,7 @@ class DFBRFeatureExtractor(torch.nn.Module): """ - def __init__(self: torch.nn.Module) -> None: + def __init__(self: DFBRFeatureExtractor) -> None: """Initialize :class:`DFBRFeatureExtractor`.""" super().__init__() output_layers_id: list[str] = ["16", "23", "30"] @@ -434,8 +434,8 @@ class DFBRegister: def __init__(self: DFBRegister, patch_size: tuple[int, int] = (224, 224)) -> None: """Initialize :class:`DFBRegister`.""" self.patch_size = patch_size - self.x_scale: list[float] = [] - self.y_scale: list[float] = [] + self.x_scale: np.ndarray + self.y_scale: np.ndarray self.feature_extractor = DFBRFeatureExtractor() # Make this function private when full pipeline is implemented. @@ -796,7 +796,7 @@ def find_points_inside_boundary(mask: np.ndarray, points: np.ndarray) -> np.ndar return PatchExtractor.filter_coordinates( mask_reader, bbox_coord, - mask.shape[::-1], + (mask.shape[1], mask.shape[0]), ) def filtering_matching_points( @@ -1521,21 +1521,21 @@ def get_patch_dimensions( """ width, height = size[0], size[1] - x = [ + x_info = [ np.linspace(1, width, width, endpoint=True), np.ones(height) * width, np.linspace(1, width, width, endpoint=True), np.ones(height), ] - x = np.array(list(itertools.chain.from_iterable(x))) + x = np.array(list(itertools.chain.from_iterable(x_info))) - y = [ + y_info = [ np.ones(width), np.linspace(1, height, height, endpoint=True), np.ones(width) * height, np.linspace(1, height, height, endpoint=True), ] - y = np.array(list(itertools.chain.from_iterable(y))) + y = np.array(list(itertools.chain.from_iterable(y_info))) points = np.array([x, y]).transpose() transform = transform * [[1, 1, 0], [1, 1, 0], [1, 1, 1]] # remove translation diff --git a/tiatoolbox/utils/metrics.py b/tiatoolbox/utils/metrics.py index f18f60db4..36a071926 100644 --- a/tiatoolbox/utils/metrics.py +++ b/tiatoolbox/utils/metrics.py @@ -103,5 +103,5 @@ def dice(gt_mask: np.ndarray, pred_mask: np.ndarray) -> float: pred_mask = pred_mask.astype(np.bool_) sum_masks = gt_mask.sum() + pred_mask.sum() if sum_masks == 0: - return np.NAN + return np.nan return 2 * np.logical_and(gt_mask, pred_mask).sum() / sum_masks