def erosion_filtration(img): ef = ErosionFiltration(n_iterations=None, n_jobs=N_JOBS) diagrams_erosion = ef.fit_transformp(img) # BC = BettiCurve() # X_betti_curves = BC.fit_transform(diagrams_Erosion) # BC.plot(X_betti_curves).show() return diagrams_erosion
def pipeline1(images): """ Binarizer --> Height Filtration, Erosion Filtration, Dilation Filtration --> Cubical Persistance --> Amp, PE return: Array of pipelines """ # Pipeline parameters bin_thresholds = [np.percentile(images[0], 93) / np.max(images[0])] directions = [ np.array([np.cos(t), np.sin(t)]) for t in np.linspace(0, 2 * np.pi, 8)[:-1] ] n_iterations = np.linspace(1, 21, 5).astype(int).tolist() features = [('bottleneck', Amplitude(metric='bottleneck', n_jobs=-1)), ('PE', PersistenceEntropy(n_jobs=-1))] # Make filtrations binned_steps = [('binarizer_{}'.format(t), Binarizer(threshold=t, n_jobs=-1)) for t in bin_thresholds] filtrations = [('height_{}'.format(d), HeightFiltration(direction=d, n_jobs=-1)) for d in directions] filtrations += [('erosion_{}'.format(i), ErosionFiltration(n_iterations=i, n_jobs=-1)) for i in n_iterations] filtrations += [('dilation_{}'.format(i), DilationFiltration(n_iterations=i, n_jobs=-1)) for i in n_iterations] # Make pipelines cubical_lower = ('cubical', CubicalPersistence(n_jobs=-1)) partial_pipeline_steps = [] partial_pipeline_steps.append([cubical_lower]) partial_pipeline_steps.append([('inverter', Inverter(n_jobs=-1)), cubical_lower]) for b, f in itertools.product(binned_steps, filtrations): partial_pipeline_steps.append( [b, f, ('cubical', CubicalPersistence(n_jobs=-1))]) feature_pipelines = [] for s, f in itertools.product(partial_pipeline_steps, features): feature_pipelines.append(Pipeline(s + [f])) return feature_pipelines
def test_erosion_fit_transform_plot(): ErosionFiltration().fit_transform_plot(images_2D, sample=0)
def test_erosion_transform(n_iterations, images, expected): erosion = ErosionFiltration(n_iterations=n_iterations) assert_almost_equal(erosion.fit_transform(images), expected)
def test_erosion_errors(): n_iterations = 'a' erosion = ErosionFiltration(n_iterations=n_iterations) with pytest.raises(TypeError): erosion.fit(images_2D)
def test_erosion_not_fitted(): erosion = ErosionFiltration() with pytest.raises(NotFittedError): erosion.transform(images_2D)
pio.renderers.default = 'plotly_mimetype' images_2D = np.stack([np.ones((3, 4)), np.concatenate([np.ones((3, 2)), np.zeros((3, 2))], axis=1), np.zeros((3, 4))], axis=0) images_3D = np.stack([np.ones((3, 4, 2)), np.concatenate([np.ones((3, 2, 2)), np.zeros((3, 2, 2))], axis=1), np.zeros((3, 4, 2))], axis=0) @pytest.mark.parametrize("transformer", [HeightFiltration(), RadialFiltration(), DilationFiltration(), ErosionFiltration(), SignedDistanceFiltration(), DensityFiltration()]) def test_invalid_input_shape(transformer): X = np.ones((1, 1, 1, 1, 1)) with pytest.raises(ValueError, match="Input of `fit`"): transformer.fit(X) def test_height_not_fitted(): height = HeightFiltration() with pytest.raises(NotFittedError): height.transform(images_2D) def test_height_errors(): direction = 'a'