graintrace.cluster_indicator#

Cluster indicators wrapping sklearn/scipy clustering over similarity metrics.

class graintrace.cluster_indicator.ClusterAnalysisIndicator(csv_path, id_col='id', coord_cols=('x', 'y', 'z'))[source]#

Bases: object

Run clustering algorithms on field data and summarize per-cluster statistics.

Parameters:
load_data()[source]#

Load CSV and populate data, features, coords.

Return type:

None

check_feature_matrix(spec)[source]#

Validate that the required feature columns for spec are numeric and finite.

Parameters:

spec (SimilarityMetric)

Return type:

None

run(method_type, spec, minimal_return=False, **kwargs)[source]#

Cluster points and return {“points”, “clusters”, “extras”}.

Parameters:
Return type:

Dict[str, Any]

run_sklearn_dbscan(spec, eps=0.5, min_samples=5, algorithm='auto', leaf_size=30, p=None, n_jobs=None, include_noise_in_summaries=False, noise_label=-1, minimal_return=False)[source]#

Cluster with sklearn DBSCAN and return points, cluster summaries, and extras.

Parameters:
Return type:

Tuple[DataFrame | None, DataFrame, Dict[str, Any]]

run_sklearn_agglomerative(spec, n_clusters=2, memory=None, connectivity=None, compute_full_tree='auto', linkage='average', distance_threshold=None, compute_distances=False, minimal_return=False)[source]#

Cluster with sklearn AgglomerativeClustering using the metric’s distance func.

Parameters:
Return type:

Tuple[DataFrame | None, DataFrame, Dict[str, Any]]

run_sklearn_optics(spec, min_samples=5, max_eps=inf, p=2, metric_params=None, cluster_method='xi', eps=None, xi=0.05, predecessor_correction=True, min_cluster_size=None, algorithm='auto', leaf_size=30, memory=None, n_jobs=None, include_noise_in_summaries=False, noise_label=-1, minimal_return=False)[source]#

Cluster with sklearn OPTICS and return points, cluster summaries, and extras.

Parameters:
Return type:

Tuple[DataFrame | None, DataFrame, Dict[str, Any]]

plot_dendrogram(Z, threshold, save_path=None, ax=None, no_labels=True)[source]#

Plot a hierarchical-clustering dendrogram with a cut threshold; return leaf info.

Parameters:
Return type:

Dict[str, Any]

run_scipy_hierarchical(spec, method='average', criterion='distance', threshold=1.0, depth=10, dendrogram_path=None, minimal_return=False)[source]#

Cluster with scipy hierarchical linkage and return points, summaries, and extras.

Parameters:
Return type:

Tuple[DataFrame | None, DataFrame, Dict[str, Any]]