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))
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/')
def test_interpolate(self, grid_size): img = ImageStack(filename='', load=False) img.data = np.zeros([10, 100, 100]) img.data[2:7, 10:-10, 10:-10] = 1 voxel_size = [4, 0.3824, 0.3824] img.extract_surfaces('data/test_data/surfaces/', voxel_size=voxel_size, reconstruct=False) surf = Surface(filename='data/test_data/surfaces/_Cell00001.csv') surf.centrate() surf.to_spherical() grid = surf.interpolate(grid_size=grid_size) self.assertEqual(len(grid), grid_size) shutil.rmtree('data/test_data/')
def test_spharm_transform(self): img = ImageStack(filename='', load=False) img.data = np.zeros([100, 100, 100]) img.data[48:52, 48:52, 48:52] = 1. voxel_size = 0.3 img.extract_surfaces('data/test_data/surfaces/', voxel_size=voxel_size, reconstruct=True) surf = Surface(filename='data/test_data/surfaces/_Cell00001.csv') surf.centrate() surf.to_spherical() grid = surf.interpolate(grid_size=10) surf.compute_spharm(grid_size=10) ngrid = surf.inverse_spharm() self.assertAlmostEqual(np.mean(np.abs(ngrid - grid)), 0, 1) shutil.rmtree('data/test_data/')