def _remodel_optics(model, target="xi", **kwargs): if target == "xi": xi = kwargs.get("xi", 0.03) min_cluster_size = kwargs.get("min_cluster_size", 0.01) min_samples = kwargs.get("min_samples", 0.03) labels = sk_cluster.cluster_optics_xi( min_samples=min_samples, min_cluster_size=min_cluster_size, xi=xi, reachability=model.reachability_, predecessor=model.predecessor_, ordering=model.ordering_) else: eps = kwargs.get("eps", 0.5) labels = sk_cluster.cluster_optics_dbscan( eps=eps, reachability=model.reachability_, core_distances=model.core_distances_, ordering=model.ordering_, ) return sort_labels(labels)
noisecolor = 'gray' # color for plotting of noisy points #%% Load the OPTICS result dirr = '/Users/nooteboom/Documents/GitHub/cluster_TM/cluster_SP/density/dens/results/' ff = np.load(dirr+'OPTICS_sp%d_smin%d.npz'%(sp, mins)) lon0 = ff['lon'] lat0 = ff['lat'] reachability = ff['reachability'] / 1000 ordering = ff['ordering'] predecessor = ff['predecessor'] core_distances = ff['core_distances'] #%% Create the clusters from the reachabilities, given the xi value labels = [] for op in opts: m, c = op[0], op[1] if m == "xi": l, _ = cluster_optics_xi(reachability, predecessor, ordering, mins, xi=c) else: l = cluster_optics_dbscan(reachability=reachability, core_distances=core_distances, ordering=ordering, eps=c) labels.append(l) norms = [] for l in labels: bounds = np.arange(-.5,np.max(l)+1.5,1) norms.append(matplotlib.colors.BoundaryNorm(bounds, len(bounds))) #%% exte=[18, 360-70, -75, 0]; latlines=[-75,-50, -25, 0, 25, 50, 75, 100]; # Read Foram data
OPTICS """ if P["OPTICS"]: optics_clustering = OPTICS(min_samples=P["MinPts"], metric="euclidean").fit(X_embedding) reachability = optics_clustering.reachability_ core_distances = optics_clustering.core_distances_ ordering = optics_clustering.ordering_ predecessor = optics_clustering.predecessor_ labels = [] for op in P["optics_params"]: m, c = op[0], op[1] if m == "xi": l, _ = cluster_optics_xi(reachability, predecessor, ordering, P["MinPts"], xi=c) else: l = cluster_optics_dbscan(reachability=reachability, core_distances=core_distances, ordering=ordering, eps=c) l = np.array([li % 20 if li>=0 else li for li in l]) labels.append(l) #cmap with 20 colors norms = [] for l in labels: bounds = np.arange(-.5,np.max(l)+1.5,1) norms.append(matplotlib.colors.BoundaryNorm(bounds, len(bounds))) #Optics results f = plt.figure(constrained_layout=True, figsize = (10, 2*len(labels))) gs = f.add_gridspec(len(labels), 3)