Example #1
0
 def addMoleculesWithXYCatF(self, x, y, cat,f):
     i3data = i3dtype.createDefaultI3Data(x.size)
     i3dtype.posSet(i3data, 'x', x)
     i3dtype.posSet(i3data, 'y', y)
     i3dtype.setI3Field(i3data, 'c', cat)
     i3dtype.setI3Field(i3data, 'fr', f)
     self.addMolecules(i3data)
 def addMoleculesWithXYAFrame(self, x, y, pa, frame):
     i3data = i3dtype.createDefaultI3Data(x.size)
     i3dtype.posSet(i3data, 'x', x)
     i3dtype.posSet(i3data, 'y', y)
     i3dtype.setI3Field(i3data, 'a', pa)
     i3dtype.setI3Field(i3data, 'fr', frame)
     self.addMolecules(i3data)
Example #3
0
 def addMoleculesWithXYAFrame(self, x, y, pa, frame):
     i3data = i3dtype.createDefaultI3Data(x.size)
     i3dtype.posSet(i3data, 'x', x)
     i3dtype.posSet(i3data, 'y', y)
     i3dtype.setI3Field(i3data, 'a', pa)
     i3dtype.setI3Field(i3data, 'fr', frame)
     self.addMolecules(i3data)
Example #4
0
 def addMoleculesWithXYZCat(self, x, y, z, cat):
     i3data = i3dtype.createDefaultI3Data(x.size)
     i3dtype.posSet(i3data, 'x', x)
     i3dtype.posSet(i3data, 'y', y)
     i3dtype.posSet(i3data, 'z', z)
     i3dtype.setI3Field(i3data, 'c', cat)
     self.addMolecules(i3data)
Example #5
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()
 def addMoleculesWithXYCatF(self, x, y, cat, f):
     i3data = i3dtype.createDefaultI3Data(x.size)
     i3dtype.posSet(i3data, 'x', x)
     i3dtype.posSet(i3data, 'y', y)
     i3dtype.setI3Field(i3data, 'c', cat)
     i3dtype.setI3Field(i3data, 'fr', f)
     self.addMolecules(i3data)
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()
 def addMoleculesWithXYZCat(self, x, y, z, cat):
     i3data = i3dtype.createDefaultI3Data(x.size)
     i3dtype.posSet(i3data, 'x', x)
     i3dtype.posSet(i3data, 'y', y)
     i3dtype.posSet(i3data, 'z', z)
     i3dtype.setI3Field(i3data, 'c', cat)
     self.addMolecules(i3data)
Example #9
0
 def addMoleculesWithXYZIFrame(self, x, y, z, pi, f):
     i3data = i3dtype.createDefaultI3Data(x.size)
     i3dtype.posSet(i3data, 'x', x)
     i3dtype.posSet(i3data, 'y', y)
     i3dtype.posSet(i3data, 'z', z)
     i3dtype.setI3Field(i3data, 'i', pi)
     i3dtype.setI3Field(i3data, 'fr', f)
     self.addMolecules(i3data)
Example #10
0
 def addMoleculesWithXYZIFrame(self, x, y, z, pi, f):
     i3data = i3dtype.createDefaultI3Data(x.size)
     i3dtype.posSet(i3data, 'x', x)
     i3dtype.posSet(i3data, 'y', y)
     i3dtype.posSet(i3data, 'z', z)
     i3dtype.setI3Field(i3data, 'i', pi)
     i3dtype.setI3Field(i3data, 'fr', f)
     self.addMolecules(i3data)
Example #11
0
def test_i3dtype_1():
    """
    Test conversion to and from the fitter format.
    """
    x_size = 100
    y_size = 100
    frame = 10
    nm_per_pixel = 100.0
    
    data_in = i3dtype.createDefaultI3Data(10)
    i3dtype.posSet(data_in, 'x', numpy.arange(10))
    i3dtype.posSet(data_in, 'y', numpy.arange(10) + 30.0)
    i3dtype.posSet(data_in, 'z', numpy.arange(10) + 60.0)
    i3dtype.setI3Field(data_in, 'fr', frame)

    peaks = i3dtype.convertToMultiFit(data_in, frame, nm_per_pixel)
    data_out = i3dtype.createFromMultiFit(peaks, frame, nm_per_pixel)

    fields = ['x', 'ax', 'w']
    for i in range(10):
        for field in fields:
            assert(abs(data_in[field][i] - data_out[field][i]) < 1.0e-6)
Example #12
0
 def addMoleculesWithXYIWFrame(self, x, y, pi, width, frame):
     i3data = i3dtype.createDefaultI3Data(x.size)
     i3dtype.posSet(i3data, 'x', x)
     i3dtype.posSet(i3data, 'y', y)
     i3dtype.setI3Field(i3data, 'i', pi)
     i3dtype.setI3Field(i3data, 'w', width)
     i3dtype.setI3Field(i3data, 'fr', frame)
     self.addMolecules(i3data)
Example #13
0
 def addMoleculesWithXYIWFrame(self, x, y, pi, width, frame):
     i3data = i3dtype.createDefaultI3Data(x.size)
     i3dtype.posSet(i3data, 'x', x)
     i3dtype.posSet(i3data, 'y', y)
     i3dtype.setI3Field(i3data, 'i', pi)
     i3dtype.setI3Field(i3data, 'w', width)
     i3dtype.setI3Field(i3data, 'fr', frame)
     self.addMolecules(i3data)
Example #14
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()
Example #15
0
 def addMoleculesWithXYI(self, x, y, pi):
     i3data = i3dtype.createDefaultI3Data(x.size)
     i3dtype.posSet(i3data, 'x', x)
     i3dtype.posSet(i3data, 'y', y)
     i3dtype.setI3Field(i3data, 'i', pi)
     self.addMolecules(i3data)
Example #16
0
 def addMoleculesWithXYI(self, x, y, pi):
     i3data = i3dtype.createDefaultI3Data(x.size)
     i3dtype.posSet(i3data, 'x', x)
     i3dtype.posSet(i3data, 'y', y)
     i3dtype.setI3Field(i3data, 'i', pi)
     self.addMolecules(i3data)
Example #17
0
    def addDAOSTORMMolecules(self, frame, xc, yc, br, be, msky, niter, sharp,
                             chi, err):
        #
        # DAOSTORM -> Insight3 format mapping.
        #
        # xc - xcenter
        # yc - ycenter
        # br - brightness -> peak height
        # be - brightness error (?) -> peak area
        # msky - background -> peak background
        # niter - fit iterations
        # sharp - sharpness (?) -> peak angle
        # chi - fit quality -> peak width
        # err - error flag -> link
        #

        i3data = i3dtype.createDefaultI3Data(xc.size)
        i3dtype.posSet(i3data, 'x', xc)
        i3dtype.posSet(i3data, 'y', yc)
        i3dtype.setI3Field(i3data, 'h', br)
        i3dtype.setI3Field(i3data, 'a', be)
        i3dtype.setI3Field(i3data, 'bg', msky)
        i3dtype.setI3Field(i3data, 'fi', niter)
        i3dtype.setI3Field(i3data, 'phi', sharp)
        i3dtype.setI3Field(i3data, 'w', chi)
        i3dtype.setI3Field(i3data, 'lk', err)

        self.addMolecules(i3data)
Example #18
0
    def addDAOSTORMMolecules(self, frame, xc, yc, br, be, msky, niter, sharp, chi, err):
        #
        # DAOSTORM -> Insight3 format mapping.
        #
        # xc - xcenter
        # yc - ycenter
        # br - brightness -> peak height
        # be - brightness error (?) -> peak area
        # msky - background -> peak background
        # niter - fit iterations
        # sharp - sharpness (?) -> peak angle
        # chi - fit quality -> peak width
        # err - error flag -> link
        #

        i3data = i3dtype.createDefaultI3Data(xc.size)
        i3dtype.posSet(i3data, 'x', xc)
        i3dtype.posSet(i3data, 'y', yc)
        i3dtype.setI3Field(i3data, 'h', br)
        i3dtype.setI3Field(i3data, 'a', be)
        i3dtype.setI3Field(i3data, 'bg', msky)
        i3dtype.setI3Field(i3data, 'fi', niter)
        i3dtype.setI3Field(i3data, 'phi', sharp)
        i3dtype.setI3Field(i3data, 'w', chi)
        i3dtype.setI3Field(i3data, 'lk', err)

        self.addMolecules(i3data)
Example #19
0
    def addDAOSTORMMolecules(self, frame, xc, yc, br, be, msky, niter, sharp,
                             chi, err):
        """
        This is for localizations identified by the original DAOSTORM
        algorithm, not the 3D-DAOSTORM algorithm.
        
        DAOSTORM -> Insight3 format mapping.
        
        xc - xcenter
        yc - ycenter
        br - brightness -> peak height
        be - brightness error (?) -> peak area
        msky - background -> peak background
        niter - fit iterations
        sharp - sharpness (?) -> peak angle
        chi - fit quality -> peak width
        err - error flag -> link
        """

        i3data = i3dtype.createDefaultI3Data(xc.size)
        i3dtype.posSet(i3data, 'x', xc)
        i3dtype.posSet(i3data, 'y', yc)
        i3dtype.setI3Field(i3data, 'h', br)
        i3dtype.setI3Field(i3data, 'a', be)
        i3dtype.setI3Field(i3data, 'bg', msky)
        i3dtype.setI3Field(i3data, 'fi', niter)
        i3dtype.setI3Field(i3data, 'phi', sharp)
        i3dtype.setI3Field(i3data, 'w', chi)
        i3dtype.setI3Field(i3data, 'lk', err)

        self.addMolecules(i3data)
Example #20
0
cx = numpy.random.uniform(low = 20.0, high = 236.0, size = clusters)
cy = numpy.random.uniform(low = 20.0, high = 236.0, size = clusters)
cz = numpy.random.uniform(low = -300.0, high = 300.0, size = clusters)

with writeinsight3.I3Writer("../data/test_clustering_list.bin") as i3_fp:
    for i in range(length):
        
        if((i % 500) == 0):
            print("Creating frame", i)

        on = (numpy.random.uniform(size = clusters) < p_on)
        number_on = numpy.count_nonzero(on)

        x = cx + numpy.random.normal(scale = 0.5, size = clusters)
        y = cy + numpy.random.normal(scale = 0.5, size = clusters)
        z = cz + numpy.random.normal(scale = 50.0, size = clusters)

        # Add background
        x = numpy.concatenate((x[on], numpy.random.uniform(high = 256.0, size = background)))
        y = numpy.concatenate((y[on], numpy.random.uniform(high = 256.0, size = background)))
        z = numpy.concatenate((z[on], numpy.random.uniform(low = -500.0, high = 500.0, size = background)))
        
        i3d = i3dtype.createDefaultI3Data(number_on + background)
        i3dtype.posSet(i3d, "x", x)
        i3dtype.posSet(i3d, "y", y)
        i3dtype.posSet(i3d, "z", z)
        i3dtype.setI3Field(i3d, "fr", i+1)

        i3_fp.addMolecules(i3d)
Example #21
0
    def addDAOSTORMMolecules(self, frame, xc, yc, br, be, msky, niter, sharp, chi, err):
        """
        This is for localizations identified by the original DAOSTORM
        algorithm, not the 3D-DAOSTORM algorithm.
        
        DAOSTORM -> Insight3 format mapping.
        
        xc - xcenter
        yc - ycenter
        br - brightness -> peak height
        be - brightness error (?) -> peak area
        msky - background -> peak background
        niter - fit iterations
        sharp - sharpness (?) -> peak angle
        chi - fit quality -> peak width
        err - error flag -> link
        """

        i3data = i3dtype.createDefaultI3Data(xc.size)
        i3dtype.posSet(i3data, 'x', xc)
        i3dtype.posSet(i3data, 'y', yc)
        i3dtype.setI3Field(i3data, 'h', br)
        i3dtype.setI3Field(i3data, 'a', be)
        i3dtype.setI3Field(i3data, 'bg', msky)
        i3dtype.setI3Field(i3data, 'fi', niter)
        i3dtype.setI3Field(i3data, 'phi', sharp)
        i3dtype.setI3Field(i3data, 'w', chi)
        i3dtype.setI3Field(i3data, 'lk', err)

        self.addMolecules(i3data)
Example #22
0
#z_planes = [-250.0, 250.0]
#z_planes = [-250.0, 250.0]
#z_planes = [-750.0, -250.0, 250.0, 750.0]
z_value = -500.0

# Load emitter locations.
i3_locs = readinsight3.loadI3File("emitters.bin")

if False:
    i3_locs = i3_locs[0]

# Make a bin file with emitter locations for each frame.
with writeinsight3.I3Writer("test_olist.bin") as i3w:
    for i in range(frames):
        i3_temp = i3_locs.copy()
        i3dtype.setI3Field(i3_temp, "fr", i + 1)
        i3dtype.posSet(i3_temp, "z", z_value)
        i3w.addMolecules(i3_temp)

# Load channel to channel mapping file.
with open("map.map", 'rb') as fp:
    mappings = pickle.load(fp)

# Create bin files for each plane.
for i, z_plane in enumerate(z_planes):
    cx = mappings["0_" + str(i) + "_x"]
    cy = mappings["0_" + str(i) + "_y"]
    i3_temp = i3_locs.copy()
    xi = i3_temp["x"]
    yi = i3_temp["y"]
    xf = cx[0] + cx[1] * xi + cx[2] * yi
Example #23
0
    # Save the molecule locations.
    a_vals = PSF.PSFIntegral(z_vals, h_vals)
    
    ax = numpy.ones(num_objects)
    ww = 2.0 * 160.0 * numpy.ones(num_objects)
    if (PSF.psf_type == "astigmatic"):
        sx_vals = objects[:,3]
        sy_vals = objects[:,4]
        ax = sy_vals/sx_vals
        ww = 2.0*160.0*numpy.sqrt(sx_vals*sy_vals)
        
    mols = i3dtype.createDefaultI3Data(num_objects)
    i3dtype.posSet(mols, 'x', x_vals + 1.0)
    i3dtype.posSet(mols, 'y', y_vals + 1.0)
    i3dtype.posSet(mols, 'z', z_vals)
    i3dtype.setI3Field(mols, 'a', a_vals)
    i3dtype.setI3Field(mols, 'h', h_vals)
    i3dtype.setI3Field(mols, 'w', ww)
    i3dtype.setI3Field(mols, 'ax', ax)
    i3dtype.setI3Field(mols, 'fr', i+1)
    i3_data.addMolecules(mols)

dax_data.close()
i3_data.close()


#
# The MIT License
#
# Copyright (c) 2016 Zhuang Lab, Harvard University
#
Example #24
0
    # Save the molecule locations.
    a_vals = PSF.PSFIntegral(z_vals, h_vals)
    
    ax = numpy.ones(num_objects)
    ww = 2.0 * 160.0 * numpy.ones(num_objects)
    if (PSF.psf_type == "astigmatic"):
        sx_vals = objects[:,3]
        sy_vals = objects[:,4]
        ax = sy_vals/sx_vals
        ww = 2.0*160.0*numpy.sqrt(sx_vals*sy_vals)
        
    mols = i3dtype.createDefaultI3Data(num_objects)
    i3dtype.posSet(mols, 'x', x_vals + 1.0)
    i3dtype.posSet(mols, 'y', y_vals + 1.0)
    i3dtype.posSet(mols, 'z', z_vals)
    i3dtype.setI3Field(mols, 'a', a_vals)
    i3dtype.setI3Field(mols, 'h', h_vals)
    i3dtype.setI3Field(mols, 'w', ww)
    i3dtype.setI3Field(mols, 'ax', ax)
    i3dtype.setI3Field(mols, 'fr', i+1)
    i3_data.addMolecules(mols)

dax_data.close()
i3_data.close()


#
# The MIT License
#
# Copyright (c) 2016 Zhuang Lab, Harvard University
#
Example #25
0
    def addMultiFitMolecules(self,
                             molecules,
                             x_size,
                             y_size,
                             frame,
                             nm_per_pixel,
                             inverted=False):
        n_molecules = molecules.shape[0]

        h = molecules[:, 0]
        if inverted:
            xc = y_size - molecules[:, 1]
            yc = x_size - molecules[:, 3]
            wx = 2.0 * molecules[:, 2] * nm_per_pixel
            wy = 2.0 * molecules[:, 4] * nm_per_pixel
        else:
            xc = molecules[:, 3] + 1
            yc = molecules[:, 1] + 1
            wx = 2.0 * molecules[:, 4] * nm_per_pixel
            wy = 2.0 * molecules[:, 2] * nm_per_pixel

        bg = molecules[:, 5]
        zc = molecules[:,
                       6] * 1000.0  # fitting is done in um, insight works in nm
        st = numpy.round(molecules[:, 7])
        err = molecules[:, 8]

        # calculate peak area, which is saved in the "a" field.
        parea = 2.0 * 3.14159 * h * molecules[:, 2] * molecules[:, 4]

        ax = wy / wx
        ww = numpy.sqrt(wx * wy)

        i3data = i3dtype.createDefaultI3Data(xc.size)
        i3dtype.posSet(i3data, 'x', xc)
        i3dtype.posSet(i3data, 'y', yc)
        i3dtype.posSet(i3data, 'z', zc)
        i3dtype.setI3Field(i3data, 'h', h)
        i3dtype.setI3Field(i3data, 'bg', bg)
        i3dtype.setI3Field(i3data, 'fi', st)
        i3dtype.setI3Field(i3data, 'a', parea)
        i3dtype.setI3Field(i3data, 'w', ww)
        i3dtype.setI3Field(i3data, 'ax', ax)
        i3dtype.setI3Field(i3data, 'fr', frame)
        i3dtype.setI3Field(i3data, 'i', err)
        self.addMolecules(i3data)