Skip to content

Commit

Permalink
Merge aecfc98 into e673dd4
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestoarbitrio committed Sep 21, 2020
2 parents e673dd4 + aecfc98 commit 262466f
Show file tree
Hide file tree
Showing 16 changed files with 554 additions and 667 deletions.
19 changes: 19 additions & 0 deletions src/histolab/exceptions.py
@@ -1,3 +1,22 @@
# encoding: utf-8

# ------------------------------------------------------------------------
# Copyright 2020 All Histolab Contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------------------


class HistolabException(Exception):
"""Histolab custom exception main class"""

Expand Down
30 changes: 28 additions & 2 deletions src/histolab/scorer.py
@@ -1,3 +1,21 @@
# encoding: utf-8

# ------------------------------------------------------------------------
# Copyright 2020 All Histolab Contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------------------

import operator
from abc import abstractmethod

Expand All @@ -16,15 +34,21 @@

@runtime_checkable
class Scorer(Protocol):
"""General scorer object"""
"""General scorer object
.. automethod:: __call__
"""

@abstractmethod
def __call__(self, tile: Tile) -> float:
raise NotImplementedError


class RandomScorer(Scorer):
"""Implement a Scorer that returns a random float score between 0 and 1."""
"""Implement a Scorer that returns a random float score between 0 and 1.
.. automethod:: __call__
"""

def __call__(self, tile: Tile) -> float:
"""Return the random score associated with the tile.
Expand All @@ -51,6 +75,8 @@ class NucleiScorer(Scorer):
.. math::
score = nuclei\_ratio \cdot tanh(tissue\_ratio)
.. automethod:: __call__
"""

def __call__(self, tile: Tile) -> float:
Expand Down
18 changes: 18 additions & 0 deletions src/histolab/tile.py
@@ -1,3 +1,21 @@
# encoding: utf-8

# ------------------------------------------------------------------------
# Copyright 2020 All Histolab Contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------------------

import os
from pathlib import Path
from typing import Callable, Union
Expand Down
22 changes: 20 additions & 2 deletions src/histolab/tiler.py
@@ -1,3 +1,21 @@
# encoding: utf-8

# ------------------------------------------------------------------------
# Copyright 2020 All Histolab Contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------------------

import csv
import os
from abc import abstractmethod
Expand Down Expand Up @@ -337,7 +355,7 @@ def __init__(
check_tissue: bool = True,
prefix: str = "",
suffix: str = ".png",
max_iter: int = 1e4,
max_iter: int = int(1e4),
):

super().__init__()
Expand Down Expand Up @@ -387,7 +405,7 @@ def max_iter(self) -> int:
return self._valid_max_iter

@max_iter.setter
def max_iter(self, max_iter_: int = 1e4):
def max_iter(self, max_iter_: int = int(1e4)):
if max_iter_ < self.n_tiles:
raise ValueError(
f"The maximum number of iterations ({max_iter_}) must be grater than or"
Expand Down
2 changes: 2 additions & 0 deletions src/histolab/types.py
Expand Up @@ -20,3 +20,5 @@

CoordinatePair = namedtuple("CoordinatePair", ("x_ul", "y_ul", "x_br", "y_br"))
Region = namedtuple("Region", ("index", "area", "bbox", "center"))

CP = CoordinatePair
1 change: 1 addition & 0 deletions src/histolab/util.py
Expand Up @@ -15,6 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------------------

import functools
import warnings
from collections import deque
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_tile.py
@@ -1,7 +1,7 @@
import pytest

from histolab.tile import Tile
from histolab.types import CoordinatePair
from histolab.types import CP

from ..fixtures import TILES

Expand All @@ -21,7 +21,7 @@ class Describe_Tile:
),
)
def it_knows_if_is_is_almost_white(self, tile_img, expected_result):
coords = CoordinatePair(0, 512, 0, 512)
coords = CP(0, 512, 0, 512)
tile = Tile(tile_img, coords)

is_almost_white = tile._is_almost_white
Expand Down

0 comments on commit 262466f

Please sign in to comment.