コード例 #1
0
    def test05_plot(self):
        path = site.getsitepackages()[0] + '/SPHARM/tests/'
        fn = path + 'data/synthetic_cell.txt'
        surf = Surface(filename=fn)
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            mesh = surf.plot_points()
            os.makedirs('data/test_data')
            mesh.save('data/test_data/points_3D.png', size=(200, 200))

        surf.centrate()
        surf.to_spherical()
        surf.Rgrid = surf.interpolate(grid_size=100)

        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            mesh = surf.plot_surface(points=False)
            mesh.save('data/test_data/surface_3D.png', size=(200, 200))

        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            mesh = surf.plot_surface(points=True)
            mesh.save('data/test_data/surface_with_points_3D.png',
                      size=(200, 200))
        self.assertEqual(os.path.exists('data/test_data/surface_3D.png'), True)
        self.assertEqual(os.path.exists('data/test_data/points_3D.png'), True)
        self.assertEqual(
            os.path.exists('data/test_data/surface_with_points_3D.png'), True)
        shutil.rmtree('data/test_data/')
コード例 #2
0
def plot_3D_surfaces(inputfolder, outputfolder, points=True, gridsize=100):
    """
    Plot 3D views of surfaces located in a given directory.

    Parameters
    ----------
    inputfolder : str
        Input directory with surfaces.
    outputfolder : str
        Output directory to save the plots.
    points : bool, optional
        If True, surface points will be displayed.
        Default is True.
    gridsize : int, optional
        Dimension of the square grid to interpolate the surface points.
        Default is 100.
    """
    files = filelib.list_subfolders(inputfolder, extensions=['csv'])

    for fn in files:
        s = Surface(filename=inputfolder + fn)
        s.centrate()
        s.to_spherical()
        s.Rgrid = s.interpolate(grid_size=gridsize)
        mesh = s.plot_surface(points=points)
        mesh.magnification = 3
        filelib.make_folders([os.path.dirname(outputfolder + fn[:-4])])
        mesh.save(outputfolder + fn[:-4] + '.png', size=(200, 200))
コード例 #3
0
def plot_inverse_shapes(inputfile, outputfolder, group='Group'):
    """
    Plot average cells shapes obtained by inverse SPHARM.

    Parameters
    ----------
    inputfile : str
        Path to the file with spectral data.
    outputfolder : str
        Directory to save the plotted distributions.
    group : str, optional
        Column in the input data sheet to use for grouping.
        Default is 'Group'.
    """

    filelib.make_folders([os.path.dirname(outputfolder)])
    stat = pd.read_csv(inputfile, sep='\t', index_col=0)
    stat['value'] = stat['real'] + stat['imag']*1j
    if 'Group' not in stat.columns:
        for name in stat['Name'].unique():
            group = name.split('/')[0]
            stat = stat.set_value(stat[stat['Name'] == name].index, 'Group', group)

    data = stat.groupby(['degree', 'order', 'Group']).mean().reset_index()
    groups = data[group].unique()
    for gr in groups:
        curdata = data[data[group] == gr]
        sp = Spectrum()
        sp.harmonics_csv = curdata
        sp.convert_to_shtools_array()
        surf = Surface()
        surf.spharm = sp
        maxdegree = np.max(sp.harmonics_csv['degree'])
        for lmax in np.arange(5, maxdegree + 1, 5):
            surf.inverse_spharm(lmax=lmax)
            surf.plot_surface(points=False).save(outputfolder + '_' + gr + '_inverse_lmax=' + str(lmax) + '.png',
                                                 size=(200, 200))

        surf.inverse_spharm(lmax=None)
        surf.plot_surface(points=False).save(outputfolder + '_' + gr + '_inverse_full.png',
                                             size=(200, 200))
コード例 #4
0
    def test07_spharm_inverse_less(self):
        path = site.getsitepackages()[0] + '/SPHARM/tests/'
        fn = path + 'data/synthetic_cell.txt'
        surf = Surface(filename=fn)
        surf.centrate()
        surf.to_spherical()
        surf.compute_spharm(grid_size=100)
        surf.inverse_spharm()
        os.makedirs('data/test_data')

        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            surf.plot_surface(points=True).save(
                'data/test_data/surface_inverse_all.png', size=(200, 200))
            surf.inverse_spharm(lmax=30)
            surf.plot_surface(points=True).save(
                'data/test_data/surface_inverse_30.png', size=(200, 200))
            surf.inverse_spharm(lmax=10)
            surf.plot_surface(points=True).save(
                'data/test_data/surface_inverse_10.png', size=(200, 200))
        self.assertEqual(
            os.path.exists('data/test_data/surface_inverse_all.png'), True)
        self.assertEqual(
            os.path.exists('data/test_data/surface_inverse_30.png'), True)
        self.assertEqual(
            os.path.exists('data/test_data/surface_inverse_10.png'), True)
        shutil.rmtree('data/test_data/')
コード例 #5
0
            files = os.listdir(path + 'surfaces/' + gr + '/')
            for fn in files:
                stat = pd.read_csv(path + 'surfaces/' + gr + '/' + fn, sep='\t', index_col=0)
                t1 = stat['Time'].unique()[0]
                stat = stat[stat['Time'] == t1]
                print(fn, len(stat))
                surface = Surface(data=stat)
                mesh = surface.plot_points(scale_factor=0.2)
                filelib.make_folders([os.path.dirname(path + 'surface_plots/' + gr + '_' + fn[:-4])])
                mesh.save(path + 'surface_plots/' + gr + '_' + fn[:-4] + '_init.png', size=(100, 100))
                mlab.clf()

                surface.centrate()
                surface.to_spherical()
                surface.compute_spharm(grid_size=120, normalize=True)
                mesh = surface.plot_surface(points=False)
                filelib.make_folders([os.path.dirname(path + 'surface_plots/' + gr + '_' + fn[:-4])])
                mesh.save(path + 'surface_plots/' + gr + '_' + fn[:-4] + '_grid.png', size=(100, 100))
                mlab.clf()

                surface.inverse_spharm(lmax=10)
                mesh = surface.plot_surface(points=False)
                filelib.make_folders([os.path.dirname(path + 'surface_plots/' + gr + '_' + fn[:-4])])
                mesh.save(path + 'surface_plots/' + gr + '_' + fn[:-4] + '_inverse_lmax=10.png', size=(100, 100))
                mlab.clf()

                surface.inverse_spharm(lmax=None)
                mesh = surface.plot_surface(points=False)
                filelib.make_folders([os.path.dirname(path + 'surface_plots/' + gr + '_' + fn[:-4])])
                mesh.save(path + 'surface_plots/' + gr + '_' + fn[:-4] + '_inverse.png', size=(100, 100))
                mlab.clf()