Ejemplo n.º 1
0
def findClusters(mlist_name, clist_name, eps, mc, ignore_z = True, ignore_category = True):
    
    # Load the data.
    pix_to_nm = 160.0

    i3_data_in = readinsight3.loadI3GoodOnly(mlist_name)

    c = i3_data_in['c']
    x = i3_data_in['xc']*pix_to_nm
    y = i3_data_in['yc']*pix_to_nm

    if ignore_z:
        print("Warning! Clustering without using localization z value!")
        z = numpy.zeros(x.size)
    else:
        z = i3_data_in['zc']

    # Perform analysis without regard to category.
    if ignore_category:
        print("Warning! Clustering without regard to category!")
        c = numpy.zeros(c.size)

    # Cluster the data.
    labels = dbscanC.dbscan(x, y, z, c, eps, mc, z_factor=1.0)

    # Save the data.    
    i3_data_out = writeinsight3.I3Writer(clist_name)
    i3dtype.setI3Field(i3_data_in, 'lk', labels)
    i3_data_out.addMolecules(i3_data_in)
    i3_data_out.close()
Ejemplo n.º 2
0
def findClusters(mlist_name, clist_name, eps, mc, ignore_z = True, ignore_category = True):
    
    # Load the data.
    pix_to_nm = 160.0

    i3_data_in = readinsight3.loadI3GoodOnly(mlist_name)

    c = i3_data_in['c']
    x = i3_data_in['xc']*pix_to_nm
    y = i3_data_in['yc']*pix_to_nm

    if ignore_z:
        print("Warning! Clustering without using localization z value!")
        z = numpy.zeros(x.size)
    else:
        z = i3_data_in['zc']

    # Perform analysis without regard to category.
    if ignore_category:
        print("Warning! Clustering without regard to category!")
        c = numpy.zeros(c.size)

    # Cluster the data.
    labels = dbscanC.dbscan(x, y, z, c, eps, mc, z_factor=1.0)

    # Save the data.    
    i3_data_out = writeinsight3.I3Writer(clist_name)
    i3dtype.setI3Field(i3_data_in, 'lk', labels)
    i3_data_out.addMolecules(i3_data_in)
    i3_data_out.close()
Ejemplo n.º 3
0
def findClusters(h5_name, eps, mc, ignore_z = True, ignore_category = True, z_factor = 1.0):
    """
    Perform DBSCAN clustering on an HDF5 localization file.

    h5_name - The name of the HDF5 file.
    eps - DBSCAN epsilon parameter (in nanometers).
    mc - DBSCAN mc parameter.
    ignore_z - Ignore localization z position when clustering.
    ignore_category - Ignore localization category when clustering.
    z_factor - Weighting of Z versus X/Y position. A value of 0.5 for
               example will make the clustering 1/2 as sensitive to
               Z position.

    Note: Because all the x/y/z location information must be loaded
          into memory for the DBSCAN algorithm there is a limit to
          the size of localization file that can be clustered.
    """
    with clSAH5Py.SAH5Clusters(h5_name) as cl_h5:
        [x, y, z, c, cl_dict] = cl_h5.getDataForClustering()

        if ignore_z:
            print("Warning! Clustering without using localization z value!")

        # Perform analysis without regard to category.
        if ignore_category:
            print("Warning! Clustering without regard to category!")
            c = numpy.zeros(c.size)

        # Convert data to nanometers
        pix_to_nm = cl_h5.getPixelSize()
        x_nm = x * pix_to_nm
        y_nm = y * pix_to_nm

        if ignore_z:
            z_nm = numpy.zeros(z.size)
        else:
            z_nm = 1000.0 * z
        
        # Cluster the data.
        labels = dbscanC.dbscan(x_nm, y_nm, z_nm, c, eps, mc, z_factor = z_factor)

        # Save the data. As an optimization we also save the x,y,z and
        # category values for each cluster with the cluster. Note that
        # these are the original units x/y in pixels and z in microns,
        # not the nanometer values used for clustering.
        #
        cl_dict["x"] = x
        cl_dict["y"] = y
        cl_dict["z"] = z
        cl_dict["category"] = c
        cl_h5.addClusters(labels, cl_dict)

        # Save clustering info.
        info = "dbscan,eps,{0:0.3f},mc,{1:d}".format(eps,mc)
        info += ",iz," + str(ignore_z)
        info += ",ic," + str(ignore_category)
        info += ",zf,{0:3f}".format(z_factor)
        cl_h5.setClusteringInfo(info)
Ejemplo n.º 4
0
def test_dbscan1():

    from storm_analysis.dbscan.dbscan_c import dbscan

    x = numpy.random.random(20)
    y = numpy.random.random(20)
    z = numpy.zeros(20)
    c = numpy.zeros(20)

    clusters = dbscan(x, y, z, c, 1.0, 10)

    for elt in clusters:
        assert (elt == 2)
Ejemplo n.º 5
0
if False:
    z = i3_data_in['zc']
else:
    print "Warning! Clustering without using localization z value!"
    z = numpy.zeros(x.size)

# Perform analysis without regard to category.
if True:
    print "Warning! Clustering without regard to category!"
    c = numpy.zeros(c.size)

# Cluster the data.
if (len(sys.argv) == 4):
    print "Using eps =", sys.argv[2], "mc =", sys.argv[3]
    labels = dbscanC.dbscan(x,
                            y,
                            z,
                            c,
                            float(sys.argv[2]),
                            int(sys.argv[3]),
                            z_factor=1.0)
else:
    print "Using eps = 80, mc = 5"
    labels = dbscanC.dbscan(x, y, z, c, 80.0, 5, z_factor=1.0)

# Save the data.
i3_data_out = writeinsight3.I3Writer(sys.argv[1][:-8] + "clusters_list.bin")
i3dtype.setI3Field(i3_data_in, 'lk', labels)
i3_data_out.addMolecules(i3_data_in)
i3_data_out.close()