# 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
    assert_array_equal(regular_watershed, regular_watershed_result)


def test_watershed_nodams():
    nodam_watershed_result = np.array([1,1,1,2,2,2,3,3,3,4,4,4])
    nodam_watershed = morpho.watershed(landscape, dams=False)
    assert_array_equal(nodam_watershed, nodam_watershed_result)


def test_watershed_seeded():
    seeds_bool = (landscape == 0)
    seeds_unique = nd.label(seeds_bool)[0]
    seeded_watershed_result = np.array([1,1,1,1,1,0,2,2,2,0,3,3])
    seeded_watershed1 = morpho.watershed(landscape, seeds_bool, dams=True)
    seeded_watershed2 = morpho.watershed(landscape, seeds_unique, dams=True)
    assert_array_equal(seeded_watershed1, seeded_watershed_result)
    assert_array_equal(seeded_watershed2, seeded_watershed_result)


def test_watershed_seeded_nodams():
    seeds_bool = landscape==0
    seeded_nodam_ws_result = np.array([1,1,1,1,1,1,2,2,2,3,3,3])
    seeded_nodam_ws = morpho.watershed(landscape,
                seeds=seeds_bool, override_skimage=True, dams=False)
    assert_array_equal(seeded_nodam_ws, seeded_nodam_ws_result)


def test_watershed_saddle_basin():
    saddle_landscape = np.array([[0,0,3],[2,1,2],[0,0,3]])
    saddle_result = np.array([[1,1,1],[0,0,0],[2,2,2]])

# 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

    assert_array_equal(regular_watershed, regular_watershed_result)


def test_watershed_nodams():
    nodam_watershed_result = np.array([1,1,1,2,2,2,3,3,3,4,4,4])
    nodam_watershed = morpho.watershed(landscape, dams=False)
    assert_array_equal(nodam_watershed, nodam_watershed_result)


def test_watershed_seeded():
    seeds_bool = (landscape == 0)
    seeds_unique = nd.label(seeds_bool)[0]
    seeded_watershed_result = np.array([1,1,1,1,1,0,2,2,2,0,3,3])
    seeded_watershed1 = morpho.watershed(landscape, seeds_bool, dams=True)
    seeded_watershed2 = morpho.watershed(landscape, seeds_unique, dams=True)
    assert_array_equal(seeded_watershed1, seeded_watershed_result)
    assert_array_equal(seeded_watershed2, seeded_watershed_result)


def test_watershed_seeded_nodams():
    seeds_bool = landscape==0
    seeded_nodam_ws_result = np.array([1,1,1,1,1,1,2,2,2,3,3,3])
    seeded_nodam_ws = morpho.watershed(landscape,
                seeds=seeds_bool, override_skimage=True, dams=False)
    assert_array_equal(seeded_nodam_ws, seeded_nodam_ws_result)


def test_watershed_saddle_basin():
    saddle_landscape = np.array([[0,0,3],[2,1,2],[0,0,3]])
    saddle_result = np.array([[1,1,1],[0,0,0],[2,2,2]])

    saddle_ws = morpho.watershed(saddle_landscape, dams=True)