Example #1
0
def frcCalc2d(mlist_name, results_name, show_plot):

    pixel_size = 160.0
    storm_scale = 8
    
    # Load the data.
    i3_grid = i3togrid.I3GData(mlist_name, scale = storm_scale)

    # Split the data (approximately) in half & generate 2D histograms.
    print("Searching for mid-point")

    # For simulations the .dax file might not actually have as many 
    # frames as the molecule list so use a hack to get the number of
    # frames in the molecule list.
    max_f = int(numpy.max(i3_grid.i3data['fr'])) + 1
    locs = round(numpy.sum(i3_grid.i3To2DGridAllChannelsMerged(fmax = max_f)))

    start = 0
    end = max_f
    half_locs = locs/2
    while ((end - start) > 1):
        mid = (end - start)/2 + start
        print("  ", start, mid, end)
        grid1 = i3_grid.i3To2DGridAllChannelsMerged(fmin = 0, fmax = mid)
        if (numpy.sum(grid1) < half_locs):
            start = mid
        else:
            end = mid

    print(" mid-point:", end)
    grid1 = i3_grid.i3To2DGridAllChannelsMerged(fmin = 0, fmax = end)
    grid2 = i3_grid.i3To2DGridAllChannelsMerged(fmin = end, fmax = max_f)

    # Compute FFT
    print("Calculating")
    grid1_fft = numpy.fft.fftshift(numpy.fft.fft2(grid1))
    grid2_fft = numpy.fft.fftshift(numpy.fft.fft2(grid2))

    grid1_fft_sqr = grid1_fft * numpy.conj(grid1_fft)
    grid2_fft_sqr = grid2_fft * numpy.conj(grid2_fft)
    grid1_grid2 = grid1_fft * numpy.conj(grid2_fft)

    if show_plot:
        arraytoimage.singleColorImage(numpy.abs(grid1_fft), "grid1")
        arraytoimage.singleColorImage(numpy.abs(grid2_fft), "grid2")

    [frc, frc_counts] = frcC.frc(grid1_fft, grid2_fft)

    # Plot results
    for i in range(frc.size):
        if (frc_counts[i] > 0):
            frc[i] = frc[i]/float(frc_counts[i])
        else:
            frc[i] = 0.0

    xvals = numpy.arange(frc.size)
    xvals = xvals/(float(grid1_fft.shape[0]) * pixel_size * (1.0/float(storm_scale)))
    frc = numpy.real(frc)

    with open(results_name, "w") as fp:
        for i in range(xvals.size):
            fp.write(str(xvals[i]) + "," + str(frc[i]) + "\n")

    if show_plot:
        fig = pyplot.figure()
        ax = fig.add_subplot(111)
        ax.scatter(xvals, frc)
        pyplot.xlim([xvals[0], xvals[-1]])
        pyplot.ylim([-0.2,1.2])
        pyplot.xlabel("Spatial Frequency (nm-1)")
        pyplot.ylabel("Correlation")
        pyplot.show()
Example #2
0
    if True:
        import os

        import storm_analysis.sa_library.arraytoimage as arraytoimage
        import storm_analysis.sa_library.datawriter as datawriter

        if (len(sys.argv) != 3):
            print("usage: <in_hres> <out_img>")
            exit()

        hres = HResFile(sys.argv[1])
        image = hres.sumFrames(verbose = True)

        ext = os.path.splitext(sys.argv[2])[1]
        if (ext == ".png"):
            arraytoimage.singleColorImage(image, sys.argv[2])
        elif (ext == ".dax"):
            datawriter.singleFrameDax(sys.argv[2], image)
        else:
            print("unrecognized extension ", ext)

#
# The MIT License
#
# Copyright (c) 2012 Zhuang Lab, Harvard University
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
Example #3
0
def frcCalc2d(mlist_name, results_name, show_plot):

    pixel_size = 160.0
    storm_scale = 8
    
    # Load the data.
    i3_grid = i3togrid.I3GData(mlist_name, scale = storm_scale)

    # Split the data (approximately) in half & generate 2D histograms.
    print("Searching for mid-point")

    # For simulations the .dax file might not actually have as many 
    # frames as the molecule list so use a hack to get the number of
    # frames in the molecule list.
    max_f = int(numpy.max(i3_grid.i3data['fr'])) + 1
    locs = round(numpy.sum(i3_grid.i3To2DGridAllChannelsMerged(fmax = max_f)))

    start = 0
    end = max_f
    half_locs = locs/2
    while ((end - start) > 1):
        mid = (end - start)/2 + start
        print("  ", start, mid, end)
        grid1 = i3_grid.i3To2DGridAllChannelsMerged(fmin = 0, fmax = mid)
        if (numpy.sum(grid1) < half_locs):
            start = mid
        else:
            end = mid

    print(" mid-point:", end)
    grid1 = i3_grid.i3To2DGridAllChannelsMerged(fmin = 0, fmax = end)
    grid2 = i3_grid.i3To2DGridAllChannelsMerged(fmin = end, fmax = max_f)

    # Compute FFT
    print("Calculating")
    grid1_fft = numpy.fft.fftshift(numpy.fft.fft2(grid1))
    grid2_fft = numpy.fft.fftshift(numpy.fft.fft2(grid2))

    grid1_fft_sqr = grid1_fft * numpy.conj(grid1_fft)
    grid2_fft_sqr = grid2_fft * numpy.conj(grid2_fft)
    grid1_grid2 = grid1_fft * numpy.conj(grid2_fft)

    if show_plot:
        arraytoimage.singleColorImage(numpy.abs(grid1_fft), "grid1")
        arraytoimage.singleColorImage(numpy.abs(grid2_fft), "grid2")

    [frc, frc_counts] = frcC.frc(grid1_fft, grid2_fft)

    # Plot results
    for i in range(frc.size):
        if (frc_counts[i] > 0):
            frc[i] = frc[i]/float(frc_counts[i])
        else:
            frc[i] = 0.0

    xvals = numpy.arange(frc.size)
    xvals = xvals/(float(grid1_fft.shape[0]) * pixel_size * (1.0/float(storm_scale)))
    frc = numpy.real(frc)

    with open(results_name, "w") as fp:
        for i in range(xvals.size):
            fp.write(str(xvals[i]) + "," + str(frc[i]) + "\n")

    if show_plot:
        fig = pyplot.figure()
        ax = fig.add_subplot(111)
        ax.scatter(xvals, frc)
        pyplot.xlim([xvals[0], xvals[-1]])
        pyplot.ylim([-0.2,1.2])
        pyplot.xlabel("Spatial Frequency (nm-1)")
        pyplot.ylabel("Correlation")
        pyplot.show()
Example #4
0
    if 1:
        import os

        import storm_analysis.sa_library.arraytoimage as arraytoimage
        import storm_analysis.sa_library.daxwriter as daxwriter

        if (len(sys.argv) != 3):
            print("usage: <in_hres> <out_img>")
            exit()

        hres = HResFile(sys.argv[1])
        image = hres.sumFrames(verbose=True)

        ext = os.path.splitext(sys.argv[2])[1]
        if (ext == ".png"):
            arraytoimage.singleColorImage(image, sys.argv[2])
        elif (ext == ".dax"):
            daxwriter.singleFrameDax(sys.argv[2], image)
        else:
            print("unrecognized extension ", ext)

#
# The MIT License
#
# Copyright (c) 2012 Zhuang Lab, Harvard University
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
Example #5
0
print(" mid-point:", end)
grid1 = i3_grid.i3To2DGridAllChannelsMerged(fmin=0, fmax=end)
grid2 = i3_grid.i3To2DGridAllChannelsMerged(fmin=end, fmax=max_f)

# Compute FFT
print("Calculating")
grid1_fft = numpy.fft.fftshift(numpy.fft.fft2(grid1))
grid2_fft = numpy.fft.fftshift(numpy.fft.fft2(grid2))

grid1_fft_sqr = grid1_fft * numpy.conj(grid1_fft)
grid2_fft_sqr = grid2_fft * numpy.conj(grid2_fft)
grid1_grid2 = grid1_fft * numpy.conj(grid2_fft)

if 1:
    arraytoimage.singleColorImage(numpy.abs(grid1_fft), "grid1")
    arraytoimage.singleColorImage(numpy.abs(grid2_fft), "grid2")

[frc, frc_counts] = frcC.frc(grid1_fft, grid2_fft)

# Plot results
for i in range(frc.size):
    if (frc_counts[i] > 0):
        frc[i] = frc[i] / float(frc_counts[i])
    else:
        frc[i] = 0.0

xvals = numpy.arange(frc.size)
xvals = xvals / (float(grid1_fft.shape[0]) * pixel_size *
                 (1.0 / float(storm_scale)))
frc = numpy.real(frc)