Exemple #1
0
    x = numpy.arange(0.0, 2.001, 0.125)
    y = numpy.array([[0.0, 1.0, 2.0], [3.0, 4.0, 5.0], [6.0, 7.0, 8.0]])

    s = Spline2D(y)

    surf = numpy.zeros((x.size, x.size))
    dx_surf = numpy.zeros((x.size, x.size))
    dy_surf = numpy.zeros((x.size, x.size))
    for i in range(x.size):
        for j in range(x.size):
            surf[i, j] = s.f(x[i], x[j])
            dx_surf[i, j] = s.dxf(x[i], x[j])
            dy_surf[i, j] = s.dyf(x[i], x[j])

    print(surf)
    #print dx_surf
    #print dy_surf

    if 0:
        surf = 100.0 + 100.0 * surf
        dx_surf = 100.0 + 100.0 * dx_surf
        dy_surf = 100.0 + 100.0 * dy_surf
        daxwriter.singleFrameDax("surf.dax", surf)
        daxwriter.singleFrameDax("dx_surf.dax", dx_surf)
        daxwriter.singleFrameDax("dy_surf.dax", dy_surf)

    #pw = pyqtgraph.plot()

    #raw_input("return to continue")
Exemple #2
0
        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
# furnished to do so, subject to the following conditions:
#
def psfToSpline(psf_name, spline_name, s_size):
    
    psf_data = pickle.load(open(psf_name, 'rb'))
    np_psf = psf_data["psf"]
    spline = False
    start = np_psf.shape[1]/2.0 - s_size - 0.5


    # 2D spline
    if (len(np_psf.shape) == 2):
        print("Generating 2D spline.")
        s_size = 2*s_size

        np_spline = numpy.zeros((s_size, s_size))
        #np_psf = np_psf/numpy.max(np_psf)
        xy_spline = spline2D.Spline2D(np_psf)
        
        x = start
        for i in range(s_size):
            y = start
            for j in range(s_size):
                np_spline[j,i] = xy_spline.f(y,x)
            
                y += 1.0
            x += 1.0

        print("Calculating spline coefficients.")
        spline = spline2D.Spline2D(np_spline)

        if True:
            import storm_analysis.sa_library.daxwriter as daxwriter
            daxwriter.singleFrameDax(os.path.join(os.path.dirname(spline_name), "spline.dax"), 1000.0*np_spline + 100)


    # 3D spline
    else:
        print("Generating 3D spline.")
        s_size = 2*s_size

        np_spline = numpy.zeros((s_size, s_size, s_size))
        xy_splines = []

        print("Generating XY splines.")
        for i in range(np_psf.shape[0]):
            xy_splines.append(spline2D.Spline2D(np_psf[i,:,:]))

        print("Generating fitting spline.")
        x = start
        for i in range(s_size):
            y = start
            for j in range(s_size):

                zvals = numpy.zeros(np_psf.shape[0])
                for k in range(np_psf.shape[0]):
                    zvals[k] = xy_splines[k].f(y,x)
                    z_spline = spline1D.Spline1D(zvals)

                max_z = float(np_psf.shape[0]) - 1.0
                inc = max_z/(float(s_size)-1.0)
                for k in range(s_size):
                    z = float(k)*inc
                    if (z > max_z):
                        z = max_z
                    np_spline[k,j,i] = z_spline.f(z)

                y += 1.0
            x += 1.0

        print("Calculating spline coefficients.")
        spline = spline3D.Spline3D(np_spline)

        if True:
            import storm_analysis.sa_library.daxwriter as daxwriter
            dxw = daxwriter.DaxWriter(os.path.join(os.path.dirname(spline_name), "spline.dax"),
                                      np_spline.shape[1],
                                      np_spline.shape[2])
            for i in range(s_size):
                dxw.addFrame(1000.0*np_spline[i,:,:] + 100)
            dxw.close()

    del psf_data["psf"]
    psf_data["spline"] = np_spline
    psf_data["coeff"] = spline.getCoeff()
    pickle.dump(psf_data, open(spline_name, 'wb'))
Exemple #4
0
def psfToSpline(psf_name, spline_name, s_size):
    
    psf_data = pickle.load(open(psf_name, 'rb'))
    np_psf = psf_data["psf"]
    spline = False
    start = np_psf.shape[1]/2.0 - s_size - 0.5


    # 2D spline
    if (len(np_psf.shape) == 2):
        print("Generating 2D spline.")
        s_size = 2*s_size

        np_spline = numpy.zeros((s_size, s_size))
        #np_psf = np_psf/numpy.max(np_psf)
        xy_spline = spline2D.Spline2D(np_psf)
        
        x = start
        for i in range(s_size):
            y = start
            for j in range(s_size):
                np_spline[j,i] = xy_spline.f(y,x)
            
                y += 1.0
            x += 1.0

        print("Calculating spline coefficients.")
        spline = spline2D.Spline2D(np_spline)

        if True:
            import storm_analysis.sa_library.daxwriter as daxwriter
            daxwriter.singleFrameDax(os.path.join(os.path.dirname(spline_name), "spline.dax"), 1000.0*np_spline + 100)


    # 3D spline
    else:
        print("Generating 3D spline.")
        s_size = 2*s_size

        np_spline = numpy.zeros((s_size, s_size, s_size))
        xy_splines = []

        print("Generating XY splines.")
        for i in range(np_psf.shape[0]):
            xy_splines.append(spline2D.Spline2D(np_psf[i,:,:]))

        print("Generating fitting spline.")
        x = start
        for i in range(s_size):
            y = start
            for j in range(s_size):

                zvals = numpy.zeros(np_psf.shape[0])
                for k in range(np_psf.shape[0]):
                    zvals[k] = xy_splines[k].f(y,x)
                    z_spline = spline1D.Spline1D(zvals)

                max_z = float(np_psf.shape[0]) - 1.0
                inc = max_z/(float(s_size)-1.0)
                for k in range(s_size):
                    z = float(k)*inc
                    if (z > max_z):
                        z = max_z
                    np_spline[k,j,i] = z_spline.f(z)

                y += 1.0
            x += 1.0

        print("Calculating spline coefficients.")
        spline = spline3D.Spline3D(np_spline)

        if True:
            import storm_analysis.sa_library.daxwriter as daxwriter
            dxw = daxwriter.DaxWriter(os.path.join(os.path.dirname(spline_name), "spline.dax"),
                                      np_spline.shape[1],
                                      np_spline.shape[2])
            for i in range(s_size):
                dxw.addFrame(1000.0*np_spline[i,:,:] + 100)
            dxw.close()

    del psf_data["psf"]
    psf_data["spline"] = np_spline
    psf_data["coeff"] = spline.getCoeff()
    pickle.dump(psf_data, open(spline_name, 'wb'))
Exemple #5
0
        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
# furnished to do so, subject to the following conditions:
#
Exemple #6
0
    x = numpy.arange(0.0, 2.001, 0.125)
    y = numpy.array([[0.0, 1.0, 2.0], [3.0, 4.0, 5.0], [6.0, 7.0, 8.0]])

    s = Spline2D(y)

    surf = numpy.zeros((x.size, x.size))
    dx_surf = numpy.zeros((x.size, x.size))
    dy_surf = numpy.zeros((x.size, x.size))
    for i in range(x.size):
        for j in range(x.size):
            surf[i, j] = s.f(x[i], x[j])
            dx_surf[i, j] = s.dxf(x[i], x[j])
            dy_surf[i, j] = s.dyf(x[i], x[j])

    print(surf)
    # print dx_surf
    # print dy_surf

    if 0:
        surf = 100.0 + 100.0 * surf
        dx_surf = 100.0 + 100.0 * dx_surf
        dy_surf = 100.0 + 100.0 * dy_surf
        daxwriter.singleFrameDax("surf.dax", surf)
        daxwriter.singleFrameDax("dx_surf.dax", dx_surf)
        daxwriter.singleFrameDax("dy_surf.dax", dy_surf)

    # pw = pyqtgraph.plot()

    # raw_input("return to continue")