Skip to content

Commit 44f7566

Browse files
committed
Documentation formatting cleanup
1 parent ef794b9 commit 44f7566

File tree

3 files changed

+52
-30
lines changed

3 files changed

+52
-30
lines changed

doc/users/mipav.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ In order to use the standalone MCR version of spm, you need to ensure that
1313
the following commands are executed at the beginning of your script:
1414

1515
.. testcode::
16-
16+
17+
1718
# location of additional JAVA libraries to use
18-
JAVALIB=/Applications/mipav/jre/Contents/Home/lib/ext/
19-
20-
# location of the MIPAV installation to use
21-
MIPAV=/Applications/mipav
22-
23-
# location of the plugin installation to use
24-
# please replace 'ThisUser' by your user name
25-
PLUGINS=/Users/ThisUser/mipav/plugins
26-
27-
export CLASSPATH=$JAVALIB/*:$MIPAV:$MIPAV/lib/*:$PLUGINS
19+
JAVALIB=/Applications/mipav/jre/Contents/Home/lib/ext/
20+
21+
# location of the MIPAV installation to use
22+
MIPAV=/Applications/mipav
23+
# location of the plugin installation to use
24+
# please replace 'ThisUser' by your user name
25+
PLUGINS=/Users/ThisUser/mipav/plugins
26+
27+
export CLASSPATH=$JAVALIB/*:$MIPAV:$MIPAV/lib/*:$PLUGINS

examples/rsfmri_vol_surface_preprocessing.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
21
#!/usr/bin/env python
2+
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
3+
# vi: set ft=python sts=4 ts=4 sw=4 et:
34
"""
45
====================================
56
rsfMRI: ANTS, FS, FSL, SPM, aCompCor
@@ -40,15 +41,15 @@
4041
4142
- `Joint Fusion Atlas <http://mindboggle.info/data/atlases/jointfusion/OASIS-TRT-20_jointfusion_DKT31_CMA_labels_in_MNI152_2mm_v2.nii.gz>`_
4243
- `MNI template <http://mindboggle.info/data/templates/ants/OASIS-30_Atropos_template_in_MNI152_2mm.nii.gz>`_
43-
4444
"""
4545

46+
4647
import os
4748

4849
from nipype.interfaces.base import CommandLine
4950
CommandLine.set_default_terminal_output('allatonce')
5051

51-
from dcmstack.extract import default_extractor
52+
5253
from dicom import read_file
5354

5455
from nipype.interfaces import (spm, fsl, Function, ants, freesurfer)
@@ -83,6 +84,7 @@
8384

8485

8586
def get_info(dicom_files):
87+
from dcmstack.extract import default_extractor
8688
"""Given a Siemens dicom file return metadata
8789
8890
Returns
@@ -111,6 +113,8 @@ def median(in_files):
111113
112114
out_file: a 3D Nifti file
113115
"""
116+
import numpy as np
117+
import nibabel as nb
114118
average = None
115119
for idx, filename in enumerate(filename_to_list(in_files)):
116120
img = nb.load(filename)
@@ -136,6 +140,9 @@ def bandpass_filter(files, lowpass_freq, highpass_freq, fs):
136140
highpass_freq: cutoff frequency for the high pass filter (in Hz)
137141
fs: sampling rate (in Hz)
138142
"""
143+
from nipype.utils.filemanip import split_filename, list_to_filename
144+
import numpy as np
145+
import nibabel as nb
139146
out_files = []
140147
for filename in filename_to_list(files):
141148
path, name, ext = split_filename(filename)
@@ -168,6 +175,7 @@ def motion_regressors(motion_params, order=0, derivatives=1):
168175
169176
motion + d(motion)/dt + d2(motion)/dt2 (linear + quadratic)
170177
"""
178+
import numpy as np
171179
out_files = []
172180
for idx, filename in enumerate(filename_to_list(motion_params)):
173181
params = np.genfromtxt(filename)
@@ -204,6 +212,9 @@ def build_filter1(motion_params, comp_norm, outliers, detrend_poly=None):
204212
-------
205213
components_file: a text file containing all the regressors
206214
"""
215+
import numpy as np
216+
import nibabel as nb
217+
from scipy.special import legendre
207218
out_files = []
208219
for idx, filename in enumerate(filename_to_list(motion_params)):
209220
params = np.genfromtxt(filename)
@@ -245,6 +256,10 @@ def extract_noise_components(realigned_file, mask_file, num_components=5,
245256
-------
246257
components_file: a text file containing the noise components
247258
"""
259+
from scipy.linalg.decomp_svd import svd
260+
import numpy as np
261+
import nibabel as nb
262+
import os
248263
imgseries = nb.load(realigned_file)
249264
components = None
250265
for filename in filename_to_list(mask_file):
@@ -261,7 +276,7 @@ def extract_noise_components(realigned_file, mask_file, num_components=5,
261276
stdX[np.isnan(stdX)] = 1.
262277
stdX[np.isinf(stdX)] = 1.
263278
X = (X - np.mean(X, axis=0))/stdX
264-
u, _, _ = sp.linalg.svd(X, full_matrices=False)
279+
u, _, _ = svd(X, full_matrices=False)
265280
if components is None:
266281
components = u[:, :num_components]
267282
else:
@@ -311,6 +326,9 @@ def extract_subrois(timeseries_file, label_file, indices):
311326
The first four columns are: freesurfer index, i, j, k positions in the
312327
label file
313328
"""
329+
from nipype.utils.filemanip import split_filename
330+
import nibabel as nb
331+
import os
314332
img = nb.load(timeseries_file)
315333
data = img.get_data()
316334
roiimg = nb.load(label_file)
@@ -331,6 +349,8 @@ def extract_subrois(timeseries_file, label_file, indices):
331349
def combine_hemi(left, right):
332350
"""Combine left and right hemisphere time series into a single text file
333351
"""
352+
import os
353+
import numpy as np
334354
lh_data = nb.load(left).get_data()
335355
rh_data = nb.load(right).get_data()
336356

@@ -367,10 +387,6 @@ def create_reg_workflow(name='registration'):
367387
outputspec.anat2target_transform : FLIRT+FNIRT transform
368388
outputspec.transformed_files : transformed files in target space
369389
outputspec.transformed_mean : mean image in target space
370-
371-
Example
372-
-------
373-
374390
"""
375391

376392
register = Workflow(name=name)
@@ -437,6 +453,7 @@ def create_reg_workflow(name='registration'):
437453
"""
438454
Apply inverse transform to take segmentations to functional space
439455
"""
456+
440457
applyxfm = MapNode(freesurfer.ApplyVolTransform(inverse=True,
441458
interp='nearest'),
442459
iterfield=['target_file'],
@@ -449,6 +466,7 @@ def create_reg_workflow(name='registration'):
449466
"""
450467
Apply inverse transform to aparc file
451468
"""
469+
452470
aparcxfm = Node(freesurfer.ApplyVolTransform(inverse=True,
453471
interp='nearest'),
454472
name='aparc_inverse_transform')
@@ -508,7 +526,6 @@ def create_reg_workflow(name='registration'):
508526
register.connect(stripper, 'out_file', reg, 'moving_image')
509527
register.connect(inputnode,'target_image', reg,'fixed_image')
510528

511-
512529
"""
513530
Concatenate the affine and ants transforms into a list
514531
"""
@@ -519,10 +536,10 @@ def create_reg_workflow(name='registration'):
519536
register.connect(convert2itk, 'itk_transform', merge, 'in2')
520537
register.connect(reg, ('composite_transform', pickfirst), merge, 'in1')
521538

522-
523539
"""
524540
Transform the mean image. First to anatomical and then to target
525541
"""
542+
526543
warpmean = Node(ants.ApplyTransforms(), name='warpmean')
527544
warpmean.inputs.input_image_type = 3
528545
warpmean.inputs.interpolation = 'BSpline'
@@ -535,7 +552,6 @@ def create_reg_workflow(name='registration'):
535552
register.connect(inputnode, 'mean_image', warpmean, 'input_image')
536553
register.connect(merge, 'out', warpmean, 'transforms')
537554

538-
539555
"""
540556
Assign all the output files
541557
"""
@@ -613,6 +629,7 @@ def create_workflow(files,
613629

614630
"""Segment and Register
615631
"""
632+
616633
registration = create_reg_workflow(name='registration')
617634
wf.connect(calc_median, 'median_file', registration, 'inputspec.mean_image')
618635
registration.inputs.inputspec.subject_id = subject_id

examples/smri_cbs_skullstripping.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
import nipype.interfaces.io as nio # Data i/o
2-
import nipype.interfaces.utility as util # utility
3-
import nipype.pipeline.engine as pe # pypeline engine
4-
import nipype.interfaces.camino as camino
5-
import nipype.interfaces.fsl as fsl
6-
import nipype.interfaces.camino2trackvis as cam2trk
7-
import nipype.algorithms.misc as misc
8-
import os
1+
#!/usr/bin/env python
2+
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
3+
# vi: set ft=python sts=4 ts=4 sw=4 et:
4+
"""
5+
========================================
6+
sMRI: USing CBS Tools for skullstripping
7+
========================================
8+
9+
This simple workflow uses SPECTRE2010 algorithm to skullstrip an MP2RAGE anatomical scan.
10+
"""
11+
12+
13+
import nipype.pipeline.engine as pe
914
from nipype.interfaces.mipav.developer import JistIntensityMp2rageMasking, MedicAlgorithmSPECTRE2010
1015

1116
wf = pe.Workflow("skullstripping")

0 commit comments

Comments
 (0)