-
Notifications
You must be signed in to change notification settings - Fork 520
/
postproc.py
127 lines (101 loc) · 3.31 KB
/
postproc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# -*- coding: utf-8 -*-
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
"""Provides interfaces to various commands provided by diffusion toolkit
"""
import os
from ..base import (
TraitedSpec,
File,
traits,
CommandLine,
InputMultiPath,
CommandLineInputSpec,
)
__docformat__ = "restructuredtext"
class SplineFilterInputSpec(CommandLineInputSpec):
track_file = File(
exists=True,
desc="file containing tracks to be filtered",
position=0,
argstr="%s",
mandatory=True,
)
step_length = traits.Float(
desc="in the unit of minimum voxel size",
position=1,
argstr="%f",
mandatory=True,
)
output_file = File(
"spline_tracks.trk",
desc="target file for smoothed tracks",
position=2,
argstr="%s",
usedefault=True,
)
class SplineFilterOutputSpec(TraitedSpec):
smoothed_track_file = File(exists=True)
class SplineFilter(CommandLine):
"""
Smoothes TrackVis track files with a B-Spline filter.
Helps remove redundant track points and segments
(thus reducing the size of the track file) and also
make tracks nicely smoothed. It will NOT change the
quality of the tracks or lose any original information.
Example
-------
>>> import nipype.interfaces.diffusion_toolkit as dtk
>>> filt = dtk.SplineFilter()
>>> filt.inputs.track_file = 'tracks.trk'
>>> filt.inputs.step_length = 0.5
>>> filt.run() # doctest: +SKIP
"""
input_spec = SplineFilterInputSpec
output_spec = SplineFilterOutputSpec
_cmd = "spline_filter"
def _list_outputs(self):
outputs = self.output_spec().get()
outputs["smoothed_track_file"] = os.path.abspath(self.inputs.output_file)
return outputs
class TrackMergeInputSpec(CommandLineInputSpec):
track_files = InputMultiPath(
File(exists=True),
desc="file containing tracks to be filtered",
position=0,
argstr="%s...",
mandatory=True,
)
output_file = File(
"merged_tracks.trk",
desc="target file for merged tracks",
position=-1,
argstr="%s",
usedefault=True,
)
class TrackMergeOutputSpec(TraitedSpec):
track_file = File(exists=True)
class TrackMerge(CommandLine):
"""
Merges several TrackVis track files into a single track
file.
An id type property tag is added to each track in the
newly merged file, with each unique id representing where
the track was originally from. When the merged file is
loaded in TrackVis, a property filter will show up in
Track Property panel. Users can adjust that to distinguish
and sub-group tracks by its id (origin).
Example
-------
>>> import nipype.interfaces.diffusion_toolkit as dtk
>>> mrg = dtk.TrackMerge()
>>> mrg.inputs.track_files = ['track1.trk','track2.trk']
>>> mrg.run() # doctest: +SKIP
"""
input_spec = TrackMergeInputSpec
output_spec = TrackMergeOutputSpec
_cmd = "track_merge"
def _list_outputs(self):
outputs = self.output_spec().get()
outputs["track_file"] = os.path.abspath(self.inputs.output_file)
return outputs