From 421a7782b72b27753111cf48232894656a0da57a Mon Sep 17 00:00:00 2001 From: "J. Borovec" Date: Wed, 22 Apr 2020 09:40:32 +0200 Subject: [PATCH] struct. docs * flake8 --- docs/source/conf.py | 9 ++++++--- docs/source/index.rst | 2 +- imsegm/classification.py | 4 ++-- imsegm/labeling.py | 6 +++--- imsegm/region_growing.py | 2 +- imsegm/utilities/data_samples.py | 8 ++++---- setup.py | 10 +++++----- 7 files changed, 22 insertions(+), 19 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 5d6608d8..789cb4c8 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -128,7 +128,7 @@ 'data-images', '*tests.*', '*.test_*', '*.so', '*.dll', - 'modules.rst', + 'api/modules.rst', '*/transform-img-plane_inter-circle.ipynb' ] @@ -258,8 +258,11 @@ def run_apidoc(_): for pkg in PACKAGES: - argv = ['-e', '-o', PATH_HERE, os.path.join(PATH_HERE, PATH_ROOT, pkg), - 'tests/*', '--force'] + argv = ['-e', + '-o', os.path.join(PATH_HERE, 'api'), + os.path.join(PATH_HERE, PATH_ROOT, pkg), + 'tests/*', + '--force'] try: # Sphinx 1.7+ from sphinx.ext import apidoc diff --git a/docs/source/index.rst b/docs/source/index.rst index 8567f868..3ec92148 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -8,7 +8,7 @@ Contents :maxdepth: 2 readme - imsegm + api/imsegm examples Indices and tables diff --git a/imsegm/classification.py b/imsegm/classification.py index 2fbcee26..67e0f9d2 100755 --- a/imsegm/classification.py +++ b/imsegm/classification.py @@ -335,8 +335,8 @@ def compute_classif_metrics(y_true, y_pred, metric_averages=METRIC_AVERAGES): eval_str = 'EVALUATION: {:<2} PRE: {:.3f} REC: {:.3f} F1: {:.3f} S: {:>6}' try: p, r, f, s = metrics.precision_recall_fscore_support(y_true, y_pred) - for l, _ in enumerate(p): - logging.debug(eval_str.format(l, p[l], r[l], f[l], s[l])) + for lb, _ in enumerate(p): + logging.debug(eval_str.format(lb, p[lb], r[lb], f[lb], s[lb])) except Exception: logging.exception('metrics.precision_recall_fscore_support') diff --git a/imsegm/labeling.py b/imsegm/labeling.py index 28e4f7d0..5e387dfd 100755 --- a/imsegm/labeling.py +++ b/imsegm/labeling.py @@ -386,8 +386,8 @@ def mask_segm_labels(img_labeling, labels, mask_init=None): mask = np.full(img_labeling.shape, False, dtype=bool) else: mask = mask_init.copy() - for l in labels: - mask = np.logical_or(mask, (img_labeling == l)) + for lb in labels: + mask = np.logical_or(mask, (img_labeling == lb)) return mask @@ -422,7 +422,7 @@ def sequence_labels_merge(labels_stack, dict_colors, labels_free, change_label=- im_labels = np.full(labels_stack.shape[1:], change_label, dtype=np.int) labels_used = [lb for lb in dict_colors if lb not in labels_free] lb_all = labels_used + labels_free + [change_label] - assert all(l in lb_all for l in np.unique(labels_stack)), 'some extra labels in image stack' + assert all(lb in lb_all for lb in np.unique(labels_stack)), 'some extra labels in image stack' # generate mask of free labels mask_free = mask_segm_labels(labels_stack, labels_free) for lb in labels_used: diff --git a/imsegm/region_growing.py b/imsegm/region_growing.py index 62f92afb..136364f7 100755 --- a/imsegm/region_growing.py +++ b/imsegm/region_growing.py @@ -1371,7 +1371,7 @@ def prepare_graphcut_variables(candidates, slic_points, slic_neighbours, assert np.max(candidates) < len(slic_points), \ 'max candidate idx: %d for %d centres' \ % (np.max(candidates), len(slic_points)) - max_slic_neighbours = max(max(l) for l in slic_neighbours) + max_slic_neighbours = max(max(lb) for lb in slic_neighbours) assert max_slic_neighbours < len(slic_points), \ 'max slic neighbours idx: %d for %d centres' \ % (max_slic_neighbours, len(slic_points)) diff --git a/imsegm/utilities/data_samples.py b/imsegm/utilities/data_samples.py index 8bd0daa2..57738f05 100644 --- a/imsegm/utilities/data_samples.py +++ b/imsegm/utilities/data_samples.py @@ -82,8 +82,8 @@ def sample_segment_vertical_2d(seg_size=SAMPLE_SEG_SIZE_2D_SMALL, """ cls_vals = [] cls_size = (seg_size[1], int(seg_size[0] / nb_labels)) - for l in range(nb_labels): - cls_vals.append(l * np.ones(cls_size)) + for lb in range(nb_labels): + cls_vals.append(lb * np.ones(cls_size)) seg = np.hstack(tuple(cls_vals)) seg = np.array(seg, dtype=np.int) return seg @@ -108,10 +108,10 @@ def sample_segment_vertical_3d(seg_size=SAMPLE_SEG_SIZE_3D_SMALL, [4, 4, 4, 4, 4]]) """ seg = [] - for l in range(int(levels)): + for lb in range(int(levels)): seg_2d = sample_segment_vertical_2d(seg_size[:2], nb_labels) for _ in range(int(seg_size[2] / levels)): - seg.append(seg_2d.copy() + l * nb_labels) + seg.append(seg_2d.copy() + lb * nb_labels) seg = np.array(seg, dtype=np.int) return seg diff --git a/setup.py b/setup.py index cb337b5a..e1afb9ff 100644 --- a/setup.py +++ b/setup.py @@ -54,11 +54,11 @@ def finalize_options(self): def _parse_requirements(file_path): with open(file_path) as fp: reqs = [r.rstrip() for r in fp.readlines() if not r.startswith('#')] - # drop all proprietary packages missing from PiPy - reqs = filter(lambda r: not r.startswith('http'), reqs) - # parse egg names if there are paths - reqs = [r[r.index(TEMP_EGG) + len(TEMP_EGG):] if TEMP_EGG in r else r for r in reqs] - return reqs + # drop all proprietary packages missing from PiPy + reqs = filter(lambda r: not r.startswith('http'), reqs) + # parse egg names if there are paths + reqs = [r[r.index(TEMP_EGG) + len(TEMP_EGG):] if TEMP_EGG in r else r for r in reqs] + return reqs setup_reqs = ['Cython', 'numpy'] # numpy v1.17 drops support for py2