def filter(input, output, **kwargs): # Load the input streamlines using the requested parameters. streamlines = load(input) streamlines.filter(**kwargs) # Save the streamlines to the output file. save(streamlines, output)
def merge(inputs, output): # Load all the input streamlines and merge them. streamlines_list = [load(i) for i in inputs] streamlines = reduce(operator.iadd, streamlines_list) # Save the streamlines to the output file. save(streamlines, output)
def setUpClass(cls): """Generates streamlines files used to test the CLI""" cls.test_dir = tempfile.TemporaryDirectory() # A file with all short streamlines. streamlines = Streamlines([ np.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0]]), np.array([[0.0, 0.0, 0.0], [0.0, 1.0, 0.0]]), np.array([[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]]), ]) filename = os.path.join(cls.test_dir.name, 'short.trk') save(streamlines, filename) # A file with a single random streamline. streamlines = Streamlines([ np.random.randn(100,3) ]) filename = os.path.join(cls.test_dir.name, 'random.trk') save(streamlines, filename) # A file with no streamlines. streamlines = Streamlines() filename = os.path.join(cls.test_dir.name, 'empty.trk') save(streamlines, filename) # A file with a bundle. points = np.array([ np.linspace(0, 100, 1000), np.zeros((1000,)), np.zeros((1000,))]).T points_list = [points + np.random.randn(*points.shape) for _ in range(100)] streamlines = Streamlines(points_list) filename = os.path.join(cls.test_dir.name, 'bundle.trk') save(streamlines, filename) # Also save the bundle with flipped orientations. flip = [np.random.rand() < 0.5 for _ in points_list] flip[0] = False points_list = [p[::-1] if f else p for f, p in zip(flip, points_list)] streamlines = Streamlines(points_list) filename = os.path.join(cls.test_dir.name, 'bundle-flipped.trk') save(streamlines, filename)
def filter(input_filename, output_filename, **kwargs): """Removes streamlines from a file based on features Removes streamlines from a file based on their features. For example, remove all streamlines with a length below 50mm using --min-length 50. Args: input_filename: The file that contains the streamlines to filter. output_filename: The file where the remaining streamlines will be saved. """ # Load the input_streamlines using the requested parameters. streamlines = load(input_filename) streamlines.filter(**kwargs) # Save the streamlines to the output file. save(streamlines, output_filename)
def smooth(input_filename, output_filename, **kwargs): """Smooths streamlines in a file Smooths streamlines using a least square b-spline. The distance between knots controls the smoothness of the output streamline with larger distances being smoother Args: input_filename: The file that contains the streamlines to smooth. output_filename: The file where the smoothed streamlines will be saved. """ # Load the input streamlines using the requested parameters. streamlines = load(input_filename) streamlines.smooth(**kwargs) # Save the streamlines to the output file. save(streamlines, output_filename)
def transform(input, output): """Transforms streamlines from one fileformat to another""" streamlines = load(input) save(streamlines, output)