Пример #1
0
def test_hdf5_to_image_4():
    """
    Test category (using tracks).
    """
    tracks = {
        "category": [1, 2],
        "x": numpy.array([10.0, 20.0]),
        "y": numpy.array([20.0, 10.0])
    }

    h5_name = storm_analysis.getPathOutputTest("test_hdf5_to_image.hdf5")
    storm_analysis.removeFile(h5_name)

    # Write data (as peaks).
    with saH5Py.SAH5Py(h5_name, is_existing=False, overwrite=True) as h5:
        h5.setMovieInformation(40, 30, 1, "")
        h5.addTracks(tracks)

    # Render image.
    image = hdf5ToImage.render2DImage(h5_name, category=1, scale=1)

    assert (image.shape[0] == 30)
    assert (image.shape[1] == 40)
    assert (image[10, 20] == 0)
    assert (image[20, 10] == 1)
Пример #2
0
def test_hdf5_to_image_3():
    """
    Test simple 2D image versus gaussian image.
    """
    tracks = {"x": numpy.array([10]), "y": numpy.array([20])}

    h5_name = storm_analysis.getPathOutputTest("test_hdf5_to_image.hdf5")
    storm_analysis.removeFile(h5_name)

    # Write data (as peaks).
    with saH5Py.SAH5Py(h5_name, is_existing=False, overwrite=True) as h5:
        h5.setMovieInformation(40, 30, 1, "")
        h5.addTracks(tracks)

    # Render image.
    im_grid = hdf5ToImage.render2DImage(h5_name, scale=1)
    im_gauss = hdf5ToImage.render2DImage(h5_name, scale=1, sigma=0.25)

    assert (numpy.allclose(im_grid, im_gauss, atol=1.0e-3, rtol=1.0e-3))
def test_hdf5_to_image_3():
    """
    Test simple 2D image versus gaussian image.
    """
    tracks = {"x" : numpy.array([10]),
              "y" : numpy.array([20])}

    h5_name = storm_analysis.getPathOutputTest("test_hdf5_to_image.hdf5")
    storm_analysis.removeFile(h5_name)

    # Write data (as peaks).
    with saH5Py.SAH5Py(h5_name, is_existing = False, overwrite = True) as h5:
        h5.setMovieInformation(40,30,1,"")
        h5.addTracks(tracks)

    # Render image.
    im_grid = hdf5ToImage.render2DImage(h5_name, scale = 1)
    im_gauss = hdf5ToImage.render2DImage(h5_name, scale = 1, sigma = 0.25)

    assert(numpy.allclose(im_grid, im_gauss, atol = 1.0e-3, rtol = 1.0e-3))
Пример #4
0
def collate():
    # We assume that there are two directories, the first with xy correction
    # only and the second with xyz correction.
    #

    # Make 2D images of the drift corrected data.
    if False:
        for adir in ["test_01/", "test_02/"]:
            im = hdf5ToImage.render2DImage(adir + "test.hdf5", sigma=0.5)
            tifffile.imsave(adir + "test_im_2d.tif", im.astype(numpy.float32))

    # Make 3D images of the drift corrected data.
    if False:
        z_edges = numpy.arange(-0.5, 0.55, 0.1)
        for adir in ["test_01/", "test_02/"]:
            images = hdf5ToImage.render3DImage(adir + "test.hdf5",
                                               z_edges,
                                               sigma=0.5)
            with tifffile.TiffWriter(adir + "test_im_3d.tif") as tf:
                for elt in images:
                    tf.save(elt.astype(numpy.float32))

    # Measure error in drift measurements.
    if True:
        print("Drift correction RMS error (nanometers):")
        for i, elt in enumerate(["drift_xy.txt", "drift_xyz.txt"]):

            print(" ", elt)

            ref = numpy.loadtxt(elt)
            exp = numpy.loadtxt("test_{0:02}/test_drift.txt".format(i + 1))

            max_len = exp.shape[0]
            for j, elt in enumerate(["X", "Y", "Z"]):
                refv = ref[:max_len, j]
                expv = exp[:, j + 1]

                # Correct for DC offset.
                expv += numpy.mean(refv - expv)

                # Calculate error (in nanometers).
                if (elt == "Z"):
                    print("  ", elt,
                          "{0:.3f}".format(numpy.std(refv - expv) * 1.0e+3))
                else:
                    print(
                        "  ", elt, "{0:.3f}".format(
                            numpy.std(refv - expv) * settings.pixel_size))
            print()
Пример #5
0
def collate():
    # We assume that there are two directories, the first with xy correction
    # only and the second with xyz correction.
    #

    # Make 2D images of the drift corrected data.
    if False:
        for adir in ["test_01/", "test_02/"]:
            im = hdf5ToImage.render2DImage(adir + "test.hdf5", sigma = 0.5)
            tifffile.imsave(adir + "test_im_2d.tif", im.astype(numpy.float32))

    # Make 3D images of the drift corrected data.
    if False:
        z_edges = numpy.arange(-0.5, 0.55, 0.1)
        for adir in ["test_01/", "test_02/"]:
            images = hdf5ToImage.render3DImage(adir + "test.hdf5", z_edges, sigma = 0.5)
            with tifffile.TiffWriter(adir + "test_im_3d.tif") as tf:
                for elt in images:
                    tf.save(elt.astype(numpy.float32))

    # Measure error in drift measurements.
    if True:
        print("Drift correction RMS error (nanometers):")
        for i, elt in enumerate(["drift_xy.txt", "drift_xyz.txt"]):

            print(" ", elt)
    
            ref = numpy.loadtxt(elt)
            exp = numpy.loadtxt("test_{0:02}/test_drift.txt".format(i+1))
        
            max_len = exp.shape[0]
            for j, elt in enumerate(["X", "Y", "Z"]):
                refv = ref[:max_len,j]
                expv = exp[:,j+1]

                # Correct for DC offset.
                expv += numpy.mean(refv - expv)

                # Calculate error (in nanometers).
                if (elt == "Z"):
                    print("  ", elt, "{0:.3f}".format(numpy.std(refv - expv) * 1.0e+3))
                else:
                    print("  ", elt, "{0:.3f}".format(numpy.std(refv - expv) * settings.pixel_size))
            print()
Пример #6
0
def test_hdf5_to_image_1():
    """
    Test simple 2D image (using localizations).
    """
    peaks = {"x": numpy.array([10.0]), "y": numpy.array([20.0])}

    h5_name = storm_analysis.getPathOutputTest("test_hdf5_to_image.hdf5")
    storm_analysis.removeFile(h5_name)

    # Write data (as peaks).
    with saH5Py.SAH5Py(h5_name, is_existing=False, overwrite=True) as h5:
        h5.setMovieInformation(40, 30, 1, "")
        h5.addLocalizations(peaks, 0)

    # Render image.
    image = hdf5ToImage.render2DImage(h5_name, scale=1)

    assert (image.shape[0] == 30)
    assert (image.shape[1] == 40)
    assert (image[10, 20] == 0)
    assert (image[20, 10] == 1)
def test_hdf5_to_image_2():
    """
    Test simple 2D image (using tracks).
    """
    tracks = {"x" : numpy.array([10.0]),
              "y" : numpy.array([20.0])}

    h5_name = storm_analysis.getPathOutputTest("test_hdf5_to_image.hdf5")
    storm_analysis.removeFile(h5_name)

    # Write data (as peaks).
    with saH5Py.SAH5Py(h5_name, is_existing = False, overwrite = True) as h5:
        h5.setMovieInformation(40,30,1,"")
        h5.addTracks(tracks)

    # Render image.
    image = hdf5ToImage.render2DImage(h5_name, scale = 1)

    assert(image.shape[0] == 30)
    assert(image.shape[1] == 40)
    assert(image[10,20] == 0)
    assert(image[20,10] == 1)