Skip to content

Commit

Permalink
RFCT Simplify checking for correct mode usage
Browse files Browse the repository at this point in the history
  • Loading branch information
luispedro committed Aug 13, 2014
1 parent d6730bc commit 222bc27
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion mahotas/_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@

modes = frozenset(mode2int.keys())

def _check_mode(mode, cval, fname):
def _checked_mode2int(mode, cval, fname):
if mode not in modes:
raise ValueError('mahotas.%s: `mode` not in %s' % (fname, modes))
if mode == 'constant' and cval != 0.:
raise NotImplementedError('Please email mahotas developers to get this implemented.')
return mode2int[mode]

_check_mode = _checked_mode2int

4 changes: 2 additions & 2 deletions mahotas/labeled.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .morph import get_structuring_elem
from . import _labeled
from .internal import _get_output
from ._filters import mode2int, modes, _check_mode
from ._filters import _checked_mode2int
import mahotas as mh

__all__ = [
Expand Down Expand Up @@ -317,7 +317,7 @@ def borders(labeled, Bc=None, out=None, output=None, mode='constant'):
Bc = get_structuring_elem(labeled, Bc)
output = _get_output(labeled, out, 'labeled.borders', bool, output=output)
output.fill(False)
return _labeled.borders(labeled, Bc, output, mode2int[mode])
return _labeled.borders(labeled, Bc, output, _checked_mode2int(mode, 0.0, 'borders'))


def bwperim(bw, n=4, mode="constant"):
Expand Down

0 comments on commit 222bc27

Please sign in to comment.