# Path: gala/morpho.py
# def complement(a):
# def remove_merged_boundaries(labels, connectivity=1):
# def morphological_reconstruction(marker, mask, connectivity=1):
# def hminima(a, thresh):
# def regional_minima(a, connectivity=1):
# def impose_minima(a, minima, connectivity=1):
# def minimum_seeds(current_seeds, min_seed_coordinates, connectivity=1):
# def split_exclusions(image, labels, exclusions, dilation=0, connectivity=1,
#     standard_seeds=False):
# def watershed(a, seeds=None, connectivity=1, mask=None, smooth_thresh=0.0, 
#         smooth_seeds=False, minimum_seed_size=0, dams=False,
#         override_skimage=False, show_progress=False):
# def multiscale_regular_seeds(off_limits, num_seeds):
# def _thin_seeds(seeds_img, step):
# def multiscale_seed_sequence(prob, l1_threshold=0, grid_density=10):
# def pipeline_compact_watershed(prob, *,
#                                invert_prob=True,
#                                l1_threshold=0,
#                                grid_density=10,
#                                compactness=0.01,
#                                n_jobs=1):
# def _euclid_dist(a, b):
# def compact_watershed(a, seeds, *, compactness=0.01, connectivity=1):
# def watershed_sequence(a, seeds=None, mask=None, axis=0, n_jobs=1, **kwargs):
# def manual_split(probs, seg, body, seeds, connectivity=1, boundary_seeds=None):
# def relabel_connected(im, connectivity=1):
# def smallest_int_dtype(number, signed=False, mindtype=None):
# def _is_container(a):
# def pad(ar, vals, axes=None):
# def juicy_center(ar, skinsize=1):
# def surfaces(ar, skinsize=1):
# def hollowed(ar, skinsize=1):
# def build_levels_dict(a):
# def build_neighbors_array(ar, connectivity=1):
# def raveled_steps_to_neighbors(shape, connectivity=1):
# def get_neighbor_idxs(ar, idxs, connectivity=1):
# def orphans(a):
# def non_traversing_segments(a):
# def damify(a, in_place=False):
# def seg_to_bdry(seg, connectivity=1):
# def undam(seg):


import os
import time
import numpy as np
from scipy import ndimage as nd
from numpy.testing import assert_array_equal, assert_array_less
from gala import morpho
    from numpy import testing


rundir = os.path.dirname(__file__)

def time_me(function):
    def wrapped(*args, **kwargs):
        start = time.time()
        r = function(*args, **kwargs)
        end = time.time()
        return r, (end-start)*1000
    return wrapped


test_idxs = list(range(4))
num_tests = len(test_idxs)
fns = [os.path.join(rundir, 'toy-data/test-%02i-probabilities.txt' % i)
       for i in test_idxs]
probs = list(map(np.loadtxt, fns))
fns = [os.path.join(rundir, 'toy-data/test-%02i-watershed.txt' % i)
       for i in test_idxs]
results = [np.loadtxt(fn, dtype=np.int32) for fn in fns]
landscape = np.array([1,0,1,2,1,3,2,0,2,4,1,0])


def test_watershed_images():

# Path: gala/morpho.py
# def complement(a):
# def remove_merged_boundaries(labels, connectivity=1):
# def morphological_reconstruction(marker, mask, connectivity=1):
# def hminima(a, thresh):
# def regional_minima(a, connectivity=1):
# def impose_minima(a, minima, connectivity=1):
# def minimum_seeds(current_seeds, min_seed_coordinates, connectivity=1):
# def split_exclusions(image, labels, exclusions, dilation=0, connectivity=1,
#     standard_seeds=False):
# def watershed(a, seeds=None, connectivity=1, mask=None, smooth_thresh=0.0, 
#         smooth_seeds=False, minimum_seed_size=0, dams=False,
#         override_skimage=False, show_progress=False):
# def multiscale_regular_seeds(off_limits, num_seeds):
# def _thin_seeds(seeds_img, step):
# def multiscale_seed_sequence(prob, l1_threshold=0, grid_density=10):
# def pipeline_compact_watershed(prob, *,
#                                invert_prob=True,
#                                l1_threshold=0,
#                                grid_density=10,
#                                compactness=0.01,
#                                n_jobs=1):
# def _euclid_dist(a, b):
# def compact_watershed(a, seeds, *, compactness=0.01, connectivity=1):
# def watershed_sequence(a, seeds=None, mask=None, axis=0, n_jobs=1, **kwargs):
# def manual_split(probs, seg, body, seeds, connectivity=1, boundary_seeds=None):
# def relabel_connected(im, connectivity=1):
# def smallest_int_dtype(number, signed=False, mindtype=None):
# def _is_container(a):
# def pad(ar, vals, axes=None):
# def juicy_center(ar, skinsize=1):
# def surfaces(ar, skinsize=1):
# def hollowed(ar, skinsize=1):
# def build_levels_dict(a):
# def build_neighbors_array(ar, connectivity=1):
# def raveled_steps_to_neighbors(shape, connectivity=1):
# def get_neighbor_idxs(ar, idxs, connectivity=1):
# def orphans(a):
# def non_traversing_segments(a):
# def damify(a, in_place=False):
# def seg_to_bdry(seg, connectivity=1):
# def undam(seg):


# Path: tests/test_watershed.py
import os
import time
import numpy as np
from scipy import ndimage as nd
from numpy.testing import assert_array_equal, assert_array_less
from gala import morpho
    from numpy import testing



rundir = os.path.dirname(__file__)

def time_me(function):
    def wrapped(*args, **kwargs):
        start = time.time()
        r = function(*args, **kwargs)
        end = time.time()
        return r, (end-start)*1000
    return wrapped


test_idxs = list(range(4))
num_tests = len(test_idxs)
fns = [os.path.join(rundir, 'toy-data/test-%02i-probabilities.txt' % i)
       for i in test_idxs]
probs = list(map(np.loadtxt, fns))
fns = [os.path.join(rundir, 'toy-data/test-%02i-watershed.txt' % i)
       for i in test_idxs]
results = [np.loadtxt(fn, dtype=np.int32) for fn in fns]
landscape = np.array([1,0,1,2,1,3,2,0,2,4,1,0])


def test_watershed_images():

    wss = [morpho.watershed(probs[i], dams=(i == 0)) for i in range(2)]