Example #1
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)
    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 #3
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 #4
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 #5
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)
Example #6
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 #7
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)
def test_i3dtype_2():
    """
    Test creation and setting position with an array.
    """
    i3_locs = i3dtype.createDefaultI3Data(10)
    i3dtype.posSet(i3_locs, 'x', numpy.arange(10))

    for i in range(10):
        assert(abs(i3_locs["x"][i] - i) < 1.0e-6)
        assert(abs(i3_locs["xc"][i] - i) < 1.0e-6)
def test_i3dtype_3():
    """
    Test creation and setting with a scalar.
    """
    i3_locs = i3dtype.createDefaultI3Data(10)
    i3dtype.posSet(i3_locs, 'x', 10.0)

    for i in range(10):
        assert(abs(i3_locs["x"][i] - 10.0) < 1.0e-6)
        assert(abs(i3_locs["xc"][i] - 10.0) < 1.0e-6)
def test_good_i3():
    mlist_name = storm_analysis.getPathOutputTest("test_i3_io_mlist.bin")

    # Create data.
    locs = i3dtype.createDefaultI3Data(100)

    # Save the data.
    with writeinsight3.I3Writer(mlist_name) as i3w:
        i3w.addMolecules(locs)

    # Read the data.
    locs = readinsight3.loadI3File(mlist_name)
    assert(locs.shape[0] == 100)
def test_bad_i3():
    mlist_name = storm_analysis.getPathOutputTest("test_i3_io_mlist.bin")

    # Create data.
    locs = i3dtype.createDefaultI3Data(100)

    # Save the data.
    i3w = writeinsight3.I3Writer(mlist_name)
    i3w.addMolecules(locs)
    i3w.fp.close()

    # Read the data.
    locs = readinsight3.loadI3File(mlist_name)
    assert(locs is None)
def test_write_read_1():
    """
    Test writing and reading.
    """
    bin_name = storm_analysis.getPathOutputTest("test_insight3io.bin")

    i3_locs = i3dtype.createDefaultI3Data(10)
    i3dtype.posSet(i3_locs, 'x', 10.0)

    with writeinsight3.I3Writer(bin_name) as i3:
        i3.addMolecules(i3_locs)

    i3_in = readinsight3.loadI3File(bin_name, verbose = False)
    assert(numpy.allclose(i3_locs['x'], i3_in['x']))
def test_write_read_3():
    """
    Test I3Reader on an empty file.
    """
    bin_name = storm_analysis.getPathOutputTest("test_insight3io.bin")

    i3_locs = i3dtype.createDefaultI3Data(10)
    i3dtype.posSet(i3_locs, 'x', 10.0)

    with writeinsight3.I3Writer(bin_name) as i3:
        pass

    i3_reader = readinsight3.I3Reader(bin_name)

    # Read localizations.
    i3_in = i3_reader.nextBlock()
    assert(i3_in is False)
def test_good_i3_metadata():
    mlist_name = storm_analysis.getPathOutputTest("test_i3_io_mlist.bin")

    # Create data.
    locs = i3dtype.createDefaultI3Data(100)

    # Save data and metadata.
    i3w = writeinsight3.I3Writer(mlist_name)
    i3w.addMolecules(locs)
    etree = ElementTree.Element("xml")
    test = ElementTree.SubElement(etree, "test")
    test.text = "test"
    i3w.closeWithMetadata(ElementTree.tostring(etree, 'ISO-8859-1'))

    # Read the data.
    locs = readinsight3.loadI3File(mlist_name)
    assert(locs.shape[0] == 100)

    # Read the metadata.
    metadata = readinsight3.loadI3Metadata(mlist_name)
    assert(metadata.find("test").text == "test")
def test_write_read_2():
    """
    Test I3Reader.
    """
    bin_name = storm_analysis.getPathOutputTest("test_insight3io.bin")

    i3_locs = i3dtype.createDefaultI3Data(10)
    i3dtype.posSet(i3_locs, 'x', 10.0)

    with writeinsight3.I3Writer(bin_name) as i3:
        i3.addMolecules(i3_locs)

    i3_reader = readinsight3.I3Reader(bin_name)

    # Read localizations.
    i3_in = i3_reader.nextBlock()
    assert(numpy.allclose(i3_locs['x'], i3_in['x']))
    assert(i3_in is not False)

    # This should return False because there are no more localizations.
    i3_in = i3_reader.nextBlock()
    assert(i3_in is False)
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)
random.seed(0)

nx = args.nx
ny = args.ny
spacing = args.spacing
z_range = args.zrange

if (nx * ny > 1):
    curz = -z_range
    z_inc = 2.0 * z_range / (nx * ny - 1)
else:
    curz = 0.0
    z_inc = 0.0

i3data = i3dtype.createDefaultI3Data(nx * ny)

curx = spacing
for i in range(nx):
    cury = spacing
    for j in range(ny):
        k = i * ny + j
        i3data['x'][k] = curx + random.random() - 0.5
        i3data['y'][k] = cury + random.random() - 0.5
        i3data['z'][k] = curz

        i3data['xc'][k] = i3data['x'][k]
        i3data['yc'][k] = i3data['y'][k]
        i3data['zc'][k] = i3data['z'][k]

        # Record emitter id in the 'i' field.
Example #18
0
 def addMoleculesWithXY(self, x, y):
     i3data = i3dtype.createDefaultI3Data(x.size)
     i3dtype.posSet(i3data, 'x', x)
     i3dtype.posSet(i3data, 'y', y)
     self.addMolecules(i3data)
 def addMoleculesWithXYFrame(self, x, y, frame):
     i3data = i3dtype.createDefaultI3Data(x.size)
     i3dtype.posSet(i3data, 'x', x)
     i3dtype.posSet(i3data, 'y', y)
     i3dtype.setI3Field(i3data, 'fr', frame)
     self.addMolecules(i3data)
 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)
 def addMoleculesWithXYZ(self, x, y, z):
     i3data = i3dtype.createDefaultI3Data(x.size)
     i3dtype.posSet(i3data, 'x', x)
     i3dtype.posSet(i3data, 'y', y)
     i3dtype.posSet(i3data, 'z', z)
     self.addMolecules(i3data)
Example #22
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 #23
0
random.seed(0)

nx = args.nx
ny = args.ny
spacing = args.spacing
z_range = args.zrange

if (nx*ny > 1):
    curz = -z_range
    z_inc = 2.0 * z_range/(nx*ny - 1)
else:
    curz = 0.0
    z_inc = 0.0

i3data = i3dtype.createDefaultI3Data(nx * ny)

curx = spacing
for i in range(nx):
    cury = spacing
    for j in range(ny):
        k = i*ny+j
        i3data['x'][k] = curx + random.random() - 0.5
        i3data['y'][k] = cury + random.random() - 0.5
        i3data['z'][k] = curz
        
        i3data['xc'][k] = i3data['x'][k]
        i3data['yc'][k] = i3data['y'][k]
        i3data['zc'][k] = i3data['z'][k]

        # Record emitter id in the 'i' field.
                    help="Stopping value for z position, default is 500nm.")

args = parser.parse_args()

# Create line segments.
lines = []
for i in range(args.nlines):
    lines.append(
        Line(x_pos=random.uniform(0.0, args.sx),
             y_pos=random.uniform(0.0, args.sy),
             z_pos=random.uniform(args.z_start, args.z_stop),
             angle=random.uniform(args.start_a, args.stop_a),
             length=random.uniform(args.minl, args.maxl)))

# Generate emitter locations.
i3data = i3dtype.createDefaultI3Data(args.nemitters)
i = 0
printed = False
while (i < args.nemitters):

    if ((i % 1000) == 0):
        if not printed:
            print("Adding point", i)
            printed = True
    else:
        printed = False

    # Get a random line.
    line = random.choice(lines)

    # Get a random point on the line.
Example #25
0
        
    # Save the image.
    dax_data.addFrame(image)

    # 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()


#
import storm_analysis.sa_library.writeinsight3 as writeinsight3

parser = argparse.ArgumentParser(description = 'Generate test data for Micrometry')

parser.add_argument('--total', dest='total', type=int, required=True,
                    help = "The total number of localizations.")
parser.add_argument('--match', dest='match', type=float, required=True,
                    help = "The fraction of localizations that match.")

args = parser.parse_args()

im_size = 512

# Create matching points.
total_match = int(args.total * args.match)
m_data = i3dtype.createDefaultI3Data(total_match)

i3dtype.posSet(m_data, "x", numpy.random.uniform(high = im_size, size = total_match))
i3dtype.posSet(m_data, "y", numpy.random.uniform(high = im_size, size = total_match))

# Create noise 1.
total_noise = args.total - total_match
n1_data = i3dtype.createDefaultI3Data(total_noise)

i3dtype.posSet(n1_data, "x", numpy.random.uniform(high = im_size, size = total_noise))
i3dtype.posSet(n1_data, "y", numpy.random.uniform(high = im_size, size = total_noise))

# Create noise 2.
n2_data = i3dtype.createDefaultI3Data(total_noise)

i3dtype.posSet(n2_data, "x", numpy.random.uniform(high = im_size, size = total_noise))
Example #27
0
zp = None
for clc in cl_centers:

    if xp is None:
        xp = numpy.random.normal(scale=args.dev, size=args.nlocs) + clc[0]
        yp = numpy.random.normal(scale=args.dev, size=args.nlocs) + clc[1]

        # Z is in nm, we'll assume a 100nm pixel size.
        zp = numpy.random.normal(scale=args.dev * 100.0,
                                 size=args.nlocs) + clc[2]
    else:
        xp = numpy.append(
            xp,
            numpy.random.normal(scale=args.dev, size=args.nlocs) + clc[0])
        yp = numpy.append(
            yp,
            numpy.random.normal(scale=args.dev, size=args.nlocs) + clc[1])
        zp = numpy.append(
            zp,
            numpy.random.normal(scale=args.dev * 100.0, size=args.nlocs) +
            clc[2])

# Create a molecule list structure & save it.
i3data = i3dtype.createDefaultI3Data(args.ncl * args.nlocs)
i3dtype.posSet(i3data, "x", xp)
i3dtype.posSet(i3data, "y", yp)
i3dtype.posSet(i3data, "z", zp)

with writeinsight3.I3Writer(args.i3bin) as i3w:
    i3w.addMolecules(i3data)