Skip to content

Commit 31968f1

Browse files
authored
Merge pull request #2039 from kesshijordan/enh_apm
ENH: Added Anisotropic Power interface to Dipy
2 parents a06fa8a + 08ce844 commit 31968f1

File tree

5 files changed

+123
-3
lines changed

5 files changed

+123
-3
lines changed

.zenodo.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@
8181
"name": "Keshavan, Anisha",
8282
"orcid": "0000-0003-3554-043X"
8383
},
84+
{
85+
"affiliation": "University of California, San Francisco",
86+
"name": "Jordan, Kesshi",
87+
"orcid": "0000-0001-6313-0580"
88+
},
89+
8490
{
8591
"affiliation": "Developer",
8692
"name": "Clark, Daniel",

doc/about.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ Citation
1313
Gorgolewski, Krzysztof J.; Esteban, Oscar; Burns, Christopher; Ziegler, Erik; Pinsard, Basile; Madison, Cindee; Waskom, Michael;
1414
Ellis, David Gage; Clark, Dav; Wong, Jason; Dayan, Michael; Manhães-Savio, Alexandre; Notter, Michael Philipp; Johnson, Hans;
1515
Dewey, Blake E; Halchenko, Yaroslav O.; Hamalainen, Carlo; Keshavan, Anisha; Clark, Daniel; Huntenburg, Julia M.; Hanke, Michael;
16-
Nichols, B. Nolan; Wassermann , Demian; Eshaghi, Arman; Markiewicz, Christopher J.; Varoquaux, Gael; Acland, Benjamin;
16+
Nichols, B. Nolan; Wassermann , Demian; Eshaghi, Arman; Markiewicz, Christopher J.; Varoquaux, Gael; Acland, Benjamin;
1717
Forbes, Jessica; Rokem, Ariel; Kong, Xiang-Zhen; Gramfort, Alexandre; Kleesiek, Jens; Schaefer, Alexander; Sikka, Sharad;
1818
Perez-Guevara, Martin Felipe; Glatard, Tristan; Iqbal, Shariq; Liu, Siqi; Welch, David; Sharp, Paul; Warner, Joshua; Kastman, Erik;
1919
Lampe, Leonie; Perkins, L. Nathan; Craddock, R. Cameron; Küttner, René; Bielievtsov, Dmytro; Geisler, Daniel; Gerhard, Stephan;
2020
Liem, Franziskus; Linkersdörfer, Janosch; Margulies, Daniel S.; Andberg, Sami Kristian; Stadler, Jörg; Steele, Christopher John;
2121
Broderick, William; Cipollini, Ben; Cooper, Gavin; Floren, Andrew; Huang, Lijie; Gonzalez, Ivan; McNamee, Daniel;
22-
Papadopoulos Orfanos, Dimitri; Pellman, John; Triplett, William; Goncalves, Mathias; Durnez, Joke; Ghosh, Satrajit (2017). Nipype:
22+
Papadopoulos Orfanos, Dimitri; Pellman, John; Triplett, William; Goncalves, Mathias; Durnez, Joke; Ghosh, Satrajit (2017). Nipype:
2323
a flexible, lightweight and extensible neuroimaging data processing framework in Python.
2424
0.13.0 Zenodo. `10.5281/zenodo.50186 <http://dx.doi.org/10.5281/zenodo.575897>`_
2525

@@ -94,7 +94,7 @@ Citation
9494
Goncalves, Mathias and
9595
Durnez, Joke and
9696
Ghosh, Satrajit},
97-
title = {{Nipype: a flexible, lightweight and extensible
97+
title = {{Nipype: a flexible, lightweight and extensible
9898
neuroimaging data processing framework in Python.
9999
0.13.0}},
100100
month = may,

nipype/interfaces/dipy/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
from .preprocess import Resample, Denoise
55
from .reconstruction import RESTORE, EstimateResponseSH, CSD
66
from .simulate import SimulateMultiTensor
7+
from .anisotropic_power import APMQball
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# -*- coding: utf-8 -*-
2+
"""Change directory to provide relative paths for doctests
3+
>>> import os
4+
>>> filepath = os.path.dirname( os.path.realpath( __file__ ) )
5+
>>> datadir = os.path.realpath(os.path.join(filepath, '../../testing/data'))
6+
>>> os.chdir(datadir)
7+
"""
8+
9+
from __future__ import print_function, division, unicode_literals, absolute_import
10+
11+
import nibabel as nb
12+
13+
from ... import logging
14+
from ..base import TraitedSpec, File, isdefined
15+
from .base import DipyDiffusionInterface, DipyBaseInterfaceInputSpec
16+
17+
IFLOGGER = logging.getLogger('interface')
18+
19+
20+
class APMQballInputSpec(DipyBaseInterfaceInputSpec):
21+
mask_file = File(exists=True,
22+
desc='An optional brain mask')
23+
24+
25+
class APMQballOutputSpec(TraitedSpec):
26+
out_file = File(exists=True)
27+
28+
29+
class APMQball(DipyDiffusionInterface):
30+
"""
31+
Calculates the anisotropic power map
32+
33+
Example
34+
-------
35+
36+
>>> import nipype.interfaces.dipy as dipy
37+
>>> apm = dipy.APMQball()
38+
>>> apm.inputs.in_file = 'diffusion.nii'
39+
>>> apm.inputs.in_bvec = 'bvecs'
40+
>>> apm.inputs.in_bval = 'bvals'
41+
>>> apm.run() # doctest: +SKIP
42+
"""
43+
input_spec = APMQballInputSpec
44+
output_spec = APMQballOutputSpec
45+
46+
def _run_interface(self, runtime):
47+
from dipy.reconst import shm
48+
from dipy.data import get_sphere
49+
from dipy.reconst.peaks import peaks_from_model
50+
51+
gtab = self._get_gradient_table()
52+
53+
img = nb.load(self.inputs.in_file)
54+
data = img.get_data()
55+
affine = img.affine
56+
mask = None
57+
if isdefined(self.inputs.mask_file):
58+
mask = nb.load(self.inputs.mask_file).get_data()
59+
60+
# Fit it
61+
model = shm.QballModel(gtab,8)
62+
sphere = get_sphere('symmetric724')
63+
peaks = peaks_from_model(model=model, data=data,
64+
relative_peak_threshold=.5,
65+
min_separation_angle=25,
66+
sphere=sphere, mask=mask)
67+
apm = shm.anisotropic_power(peaks.shm_coeff)
68+
out_file = self._gen_filename('apm')
69+
nb.Nifti1Image(apm.astype("float32"), affine).to_filename(out_file)
70+
IFLOGGER.info('APM qball image saved as {i}'.format(i=out_file))
71+
72+
return runtime
73+
74+
def _list_outputs(self):
75+
outputs = self._outputs().get()
76+
outputs['out_file'] = self._gen_filename('apm')
77+
78+
return outputs
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from __future__ import unicode_literals
3+
from ..anisotropic_power import APMQball
4+
5+
6+
def test_APMQball_inputs():
7+
input_map = dict(b0_thres=dict(usedefault=True,
8+
),
9+
ignore_exception=dict(nohash=True,
10+
usedefault=True,
11+
),
12+
in_bval=dict(mandatory=True,
13+
),
14+
in_bvec=dict(mandatory=True,
15+
),
16+
in_file=dict(mandatory=True,
17+
),
18+
mask_file=dict(),
19+
out_prefix=dict(),
20+
)
21+
inputs = APMQball.input_spec()
22+
23+
for key, metadata in list(input_map.items()):
24+
for metakey, value in list(metadata.items()):
25+
assert getattr(inputs.traits()[key], metakey) == value
26+
27+
28+
def test_APMQball_outputs():
29+
output_map = dict(out_file=dict(),
30+
)
31+
outputs = APMQball.output_spec()
32+
33+
for key, metadata in list(output_map.items()):
34+
for metakey, value in list(metadata.items()):
35+
assert getattr(outputs.traits()[key], metakey) == value

0 commit comments

Comments
 (0)