Skip to content

Commit

Permalink
try using entry_points
Browse files Browse the repository at this point in the history
  • Loading branch information
Jizong committed Aug 28, 2019
1 parent 4f1a9b7 commit f9e3561
Show file tree
Hide file tree
Showing 5 changed files with 263 additions and 3 deletions.
2 changes: 1 addition & 1 deletion deepclustering/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ConfigManger:
DEFAULT_CONFIG = ""

def __init__(
self, DEFAULT_CONFIG_PATH: str = None, verbose=True, integrality_check=True
self, DEFAULT_CONFIG_PATH: str = None, verbose=True, integrality_check=True
) -> None:
self.parsed_args: Dict[str, Any] = YAMLArgParser(verbose=verbose)
if DEFAULT_CONFIG_PATH is None:
Expand Down
1 change: 1 addition & 0 deletions deepclustering/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .general import *
from .type_check import *
from .warnings import _warnings
from .yaml_parser import *
234 changes: 234 additions & 0 deletions deepclustering/utils/type_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
import collections
import numbers
import sys
import types

import numpy as np
import six


def is_np_array(val):
"""
Checks whether a variable is a numpy array.
Parameters
----------
val
The variable to check.
Returns
-------
out : bool
True if the variable is a numpy array. Otherwise False.
"""
# using np.generic here via isinstance(val, (np.ndarray, np.generic)) seems to also fire for scalar numpy values
# even though those are not arrays
return isinstance(val, np.ndarray)


def is_np_scalar(val):
"""
Checks whether a variable is a numpy scalar.
Parameters
----------
val
The variable to check.
Returns
-------
out : bool
True if the variable is a numpy scalar. Otherwise False.
"""
# Note that isscalar() alone also fires for thinks like python strings
# or booleans.
# The isscalar() was added to make this function not fire for non-scalar
# numpy types. Not sure if it is necessary.
return isinstance(val, np.generic) and np.isscalar(val)


def is_single_integer(val):
"""
Checks whether a variable is an integer.
Parameters
----------
val
The variable to check.
Returns
-------
bool
True if the variable is an integer. Otherwise False.
"""
return isinstance(val, numbers.Integral) and not isinstance(val, bool)


def is_single_float(val):
"""
Checks whether a variable is a float.
Parameters
----------
val
The variable to check.
Returns
-------
bool
True if the variable is a float. Otherwise False.
"""
return isinstance(val, numbers.Real) and not is_single_integer(val) and not isinstance(val, bool)


def is_single_number(val):
"""
Checks whether a variable is a number, i.e. an integer or float.
Parameters
----------
val
The variable to check.
Returns
-------
bool
True if the variable is a number. Otherwise False.
"""
return is_single_integer(val) or is_single_float(val)


def is_iterable(val):
"""
Checks whether a variable is iterable.
Parameters
----------
val
The variable to check.
Returns
-------
bool
True if the variable is an iterable. Otherwise False.
"""
return isinstance(val, collections.Iterable)


# TODO convert to is_single_string() or rename is_single_integer/float/number()
def is_string(val):
"""
Checks whether a variable is a string.
Parameters
----------
val
The variable to check.
Returns
-------
bool
True if the variable is a string. Otherwise False.
"""
return isinstance(val, six.string_types)


def is_single_bool(val):
"""
Checks whether a variable is a boolean.
Parameters
----------
val
The variable to check.
Returns
-------
bool
True if the variable is a boolean. Otherwise False.
"""
return type(val) == type(True)


def is_integer_array(val):
"""
Checks whether a variable is a numpy integer array.
Parameters
----------
val
The variable to check.
Returns
-------
bool
True if the variable is a numpy integer array. Otherwise False.
"""
return is_np_array(val) and issubclass(val.dtype.type, np.integer)


def is_float_array(val):
"""
Checks whether a variable is a numpy float array.
Parameters
----------
val
The variable to check.
Returns
-------
bool
True if the variable is a numpy float array. Otherwise False.
"""
return is_np_array(val) and issubclass(val.dtype.type, np.floating)


def is_callable(val):
"""
Checks whether a variable is a callable, e.g. a function.
Parameters
----------
val
The variable to check.
Returns
-------
bool
True if the variable is a callable. Otherwise False.
"""
# python 3.x with x <= 2 does not support callable(), apparently
if sys.version_info[0] == 3 and sys.version_info[1] <= 2:
return hasattr(val, '__call__')
else:
return callable(val)


def is_generator(val):
"""
Checks whether a variable is a generator.
Parameters
----------
val
The variable to check.
Returns
-------
bool
True is the variable is a generator. Otherwise False.
"""
return isinstance(val, types.GeneratorType)
15 changes: 15 additions & 0 deletions deepclustering/viewer/Viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,21 @@ def _next_slice(ax):
ax.set_title(f'{ax.subject_name} @ plane:{ax.index} with {ax.mask_name}')


def main():
args = get_parser()
V = Volume(
args.img_source,
args.gt_folders,
group_pattern=args.group_pattern,
img_extension=args.img_extension,
crop=args.crop,
mapping=args.mapping
)

Viewer = Multi_Slice_Viewer(V, shuffle_subject=args.shuffle, n_subject=args.n_subject)
Viewer.show()


if __name__ == '__main__':
'''
python admm_research/postprocessing/Viewer.py --img_source=admm_research/dataset/ACDC-2D-All/val/Img --gt_folders admm_research/dataset/ACDC-2D-All/val/GT archives/LV_prior/Livia/fs/iter1000/best/ archives/LV_prior/Livia/gc_size/iter1000/best/ archives/LV_prior/Livia/size/iter1000/best/ --group_pattern='patient\d+_\d+' --crop 70
Expand Down
14 changes: 12 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import pathlib

from setuptools import setup, find_packages

HERE = pathlib.Path(__file__).parent
README = (HERE / "README.md").read_text()

setup(
name="deepclustering",
version="1.0.0",
packages=find_packages(),
url="https://github.com/jizongFox/deep-clustering-toolbox",
license="",
author="jizong",
license="MIT ",
author="Jizong Peng",
author_email="jizong.peng.1@etsmtl.net",
description="",
install_requires=[
Expand Down Expand Up @@ -36,4 +41,9 @@
"pyyaml",
"termcolor"
],
entry_points = {
"console_script":[
"viewer=deepclustering.viewer.Viewer:main",
]
},
)

0 comments on commit f9e3561

Please sign in to comment.