Skip to content

Commit

Permalink
Deprecating AvalancheSegmenter for GooseEYE.ClusterLabeller
Browse files Browse the repository at this point in the history
  • Loading branch information
tdegeus committed Dec 6, 2023
1 parent 5f087d4 commit 1bdf28c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
30 changes: 19 additions & 11 deletions examples/extremal_avalanche.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
import numpy as np

try:
import cppcolormap as cm
import GooseEYE as eye
import matplotlib as mpl
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
import cppcolormap as cm

plot = True
except ImportError:
Expand All @@ -27,33 +28,40 @@
avalanche = epm.Avalanche()
avalanche.makeWeakestFailureSteps(system, L * L, allow_stable=True)

segmenter = epm.allocate_AvalancheSegmenter(shape=system.shape, idx=avalanche.idx, t=avalanche.t)
segmenter.advance(L * L)

# renumber labels by cluster size: background, then largest to smallest clusters
n = np.bincount(segmenter.labels.ravel().astype(int), minlength=segmenter.nlabels)
segmenter.reorder([0] + list(1 + np.argsort(n[1:])[::-1]))
S = np.bincount(avalanche.idx.astype(int), minlength=system.size).reshape(system.shape)

if plot:
segmenter = eye.ClusterLabeller(shape=system.shape, periodic=True)
segmenter.add_points(np.copy(avalanche.idx))
labels = segmenter.labels

# renumber labels by cluster size: background, then largest to smallest clusters
sizes = eye.labels_sizes(labels)
sorter = np.argsort(sizes[:, 1])[::-1]
assert sorter[0] == 0
rename = np.zeros_like(sorter)
rename[sorter] = np.arange(sorter.size)
labels = eye.labels_rename(labels, np.array([sizes[:, 0], rename]).T)

fig, axes = plt.subplots(ncols=2, figsize=(8 * 2, 6))

ax = axes[0]

n = np.max(segmenter.s)
n = np.max(S)
cmap = np.vstack((np.ones((1, 3)), cm.jet(n)))
cmap = mpl.colors.ListedColormap(cmap, name="myColorMap", N=cmap.shape[0])
im = ax.imshow(segmenter.s, interpolation="nearest", cmap=cmap, clim=[0, n])
im = ax.imshow(S, interpolation="nearest", cmap=cmap, clim=[0, n])

div = make_axes_locatable(ax)
cax = div.append_axes("bottom", size="5%", pad=0.4)
cbar = plt.colorbar(im, cax=cax, orientation="horizontal")

ax = axes[1]

n = np.max(segmenter.labels)
n = np.max(labels)
cmap = np.vstack((np.ones((1, 3)), cm.Dark2(n)))
cmap = mpl.colors.ListedColormap(cmap, name="myColorMap", N=cmap.shape[0])
im = ax.imshow(segmenter.labels, interpolation="nearest", cmap=cmap, clim=[0, n])
im = ax.imshow(labels, interpolation="nearest", cmap=cmap, clim=[0, n])

div = make_axes_locatable(ax)
cax = div.append_axes("bottom", size="5%", pad=0.4)
Expand Down
3 changes: 2 additions & 1 deletion include/GooseEPM/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -2133,7 +2133,7 @@ inline array_type::tensor<size_t, 1> cumsum_n_unique(const array_type::tensor<si
* Before calling either `all(segmenter.s == 0)` and `all(segmenter.labels == 0)`.
*/
template <size_t Dimension>
class AvalancheSegmenter {
class [[deprecated("Use GooseEYE instead")]] AvalancheSegmenter {
public:
static constexpr size_t Dim = Dimension; ///< Dimensionality of the system.

Expand Down Expand Up @@ -2188,6 +2188,7 @@ class AvalancheSegmenter {
const array_type::tensor<double, 1>& t
)
{
GOOSEEPM_WARNING_PYTHON("AvalancheSegmenter is deprecated, use GooseEYE instead.");
m_shape = shape;
m_idx = idx;
m_time = t;
Expand Down

0 comments on commit 1bdf28c

Please sign in to comment.