Example #1
0
def cluster_data(data, ov_min=10, ov_min1=0.2):
    cl = Clustering(ov_min, ov_min1)
    cl.fill_clusters(data['x1'], data['x2'])

    c_labels = cl.clabels
    nhits = len(c_labels)
    n_clust = cl.ncl
    x1cl = cl.cluster_x1
    x2cl = cl.cluster_x2
    ycl = []
    pcentcl = []
    namecl = []
    detailcl = []
    x1tcl = []
    x2tcl = []
    dxtcl = []
    for i in range(0,n_clust):
        ycl.append(float(i+1)/2.)
        for j in range(0,nhits):
            if c_labels[j]==i:
                pcentcl.append(data['pcent'][j])
                namecl.append(data['name'][j])
                detailcl.append(data['detail'][j])
                x1tcl.append(data['x1t'][j])
                x2tcl.append(data['x2t'][j])
                dxtcl.append(data['dxt'][j])
                break

    new_data = dict(x1=x1cl, x2=x2cl, dx=[end-beg for beg,end in zip(x1cl,x2cl)],
                    xm=[(beg+end)/2 for beg,end in zip(x1cl,x2cl)],
                    x1t=x1tcl, x2t=x2tcl, dxt=dxtcl,
                    y=ycl, nhits=cl.nhits, name=namecl, pcent=pcentcl, detail=detailcl)

    return new_data, n_clust
Example #2
0
def filter_repeated_hits(data):
    cl = Clustering(10, 0.1) # cluster with default values
    cl.fill_clusters(data['x1'], data['x2'])

    toDelete = [False]*len(cl.clabels)
    for icl in range(cl.ncl): # loop over clusters
        if cl.nhits[icl]>50:
            counter = 0
            for i in range(len(cl.clabels)): # loop over hits
                if cl.clabels[i]==icl:
                    counter = counter + 1
                    if counter>50:
                        toDelete[i] = True

    for key in data.keys():
        data[key][:] = [value for value,flag in zip(data[key],toDelete) if not flag]
    return data
Example #3
0
def cluster_pred(x1l, x2l, ov_min=10, ov_min1=0.2):
    cl = Clustering(ov_min, ov_min1)
    cl.fill_clusters(x1l, x2l)

    return cl.clabels, cl.ncl