Skip to content

Commit

Permalink
address CR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestoarbitrio committed Sep 4, 2020
1 parent 379baa1 commit 056eebf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
42 changes: 21 additions & 21 deletions src/histolab/slide.py
Expand Up @@ -121,7 +121,7 @@ def extract_tile(self, coords: CoordinatePair, level: int) -> Tile:
Image containing the selected tile.
"""

if not self._valid_coordinates(coords):
if not self._has_valid_coords(coords):
# OpenSlide doesn't complain if the coordinates for extraction are wrong,
# but it returns an odd image.
raise ValueError(
Expand Down Expand Up @@ -326,6 +326,26 @@ def _breadcumb(self, directory_path: str, scale_factor: int = 32) -> str:
)
return final_path

def _has_valid_coords(self, coords: CoordinatePair) -> bool:
"""Check if ``coords`` are valid 0-level coordinates.
Parameters
----------
coords : CoordinatePair
Coordinates at level 0 to check
Returns
-------
bool
True if the coordinates are valid, False otherwise
"""
return (
0 <= coords.x_ul < self.dimensions[0]
and 0 <= coords.x_br < self.dimensions[0]
and 0 <= coords.y_ul < self.dimensions[1]
and 0 <= coords.y_br < self.dimensions[1]
)

@lazyproperty
def _main_tissue_areas_mask_filters(self) -> imf.Compose:
"""Return a filters composition to get a binary mask of the main tissue regions.
Expand Down Expand Up @@ -431,26 +451,6 @@ def _thumbnail_size(self) -> Tuple:
]
)

def _valid_coordinates(self, coords: CoordinatePair) -> bool:
"""Check if ``coords`` are valid 0-level coordinates.
Parameters
----------
coords : CoordinatePair
Coordinates at level 0 to check
Returns
-------
bool
True if the coordinates are valid, False otherwise
"""
return (
0 <= coords.x_ul < self.dimensions[0]
and 0 <= coords.x_br < self.dimensions[0]
and 0 <= coords.y_ul < self.dimensions[1]
and 0 <= coords.y_br < self.dimensions[1]
)

@lazyproperty
def _wsi(self) -> Union[openslide.OpenSlide, openslide.ImageSlide]:
"""Open the slide and returns an openslide object
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_slide.py
Expand Up @@ -472,7 +472,7 @@ def it_knows_if_coords_are_valid(self, valid_coords_fixture, tmpdir):
slide_path = os.path.join(tmp_path_, "mywsi.png")
slide = Slide(slide_path, "processed")

_are_valid = slide._valid_coordinates(coords)
_are_valid = slide._has_valid_coords(coords)

assert type(_are_valid) == bool
assert _are_valid == expected_result
Expand Down

0 comments on commit 056eebf

Please sign in to comment.