Skip to content

ENH: Added Anisotropic Power interface to Dipy #2039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .zenodo.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@
"name": "Keshavan, Anisha",
"orcid": "0000-0003-3554-043X"
},
{
"affiliation": "University of California, San Francisco",
"name": "Jordan, Kesshi",
"orcid": "0000-0001-6313-0580"
},

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

Expand Down Expand Up @@ -94,7 +94,7 @@ Citation
Goncalves, Mathias and
Durnez, Joke and
Ghosh, Satrajit},
title = {{Nipype: a flexible, lightweight and extensible
title = {{Nipype: a flexible, lightweight and extensible
neuroimaging data processing framework in Python.
0.13.0}},
month = may,
Expand Down
1 change: 1 addition & 0 deletions nipype/interfaces/dipy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
from .preprocess import Resample, Denoise
from .reconstruction import RESTORE, EstimateResponseSH, CSD
from .simulate import SimulateMultiTensor
from .anisotropic_power import APMQball
78 changes: 78 additions & 0 deletions nipype/interfaces/dipy/anisotropic_power.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# -*- coding: utf-8 -*-
"""Change directory to provide relative paths for doctests
>>> import os
>>> filepath = os.path.dirname( os.path.realpath( __file__ ) )
>>> datadir = os.path.realpath(os.path.join(filepath, '../../testing/data'))
>>> os.chdir(datadir)
"""

from __future__ import print_function, division, unicode_literals, absolute_import

import nibabel as nb

from ... import logging
from ..base import TraitedSpec, File, isdefined
from .base import DipyDiffusionInterface, DipyBaseInterfaceInputSpec

IFLOGGER = logging.getLogger('interface')


class APMQballInputSpec(DipyBaseInterfaceInputSpec):
mask_file = File(exists=True,
desc='An optional brain mask')


class APMQballOutputSpec(TraitedSpec):
out_file = File(exists=True)


class APMQball(DipyDiffusionInterface):
"""
Calculates the anisotropic power map

Example
-------

>>> import nipype.interfaces.dipy as dipy
>>> apm = dipy.APMQball()
>>> apm.inputs.in_file = 'diffusion.nii'
>>> apm.inputs.in_bvec = 'bvecs'
>>> apm.inputs.in_bval = 'bvals'
>>> apm.run() # doctest: +SKIP
"""
input_spec = APMQballInputSpec
output_spec = APMQballOutputSpec

def _run_interface(self, runtime):
from dipy.reconst import shm
from dipy.data import get_sphere
from dipy.reconst.peaks import peaks_from_model

gtab = self._get_gradient_table()

img = nb.load(self.inputs.in_file)
data = img.get_data()
affine = img.affine
mask = None
if isdefined(self.inputs.mask_file):
mask = nb.load(self.inputs.mask_file).get_data()

# Fit it
model = shm.QballModel(gtab,8)
sphere = get_sphere('symmetric724')
peaks = peaks_from_model(model=model, data=data,
relative_peak_threshold=.5,
min_separation_angle=25,
sphere=sphere, mask=mask)
apm = shm.anisotropic_power(peaks.shm_coeff)
out_file = self._gen_filename('apm')
nb.Nifti1Image(apm.astype("float32"), affine).to_filename(out_file)
IFLOGGER.info('APM qball image saved as {i}'.format(i=out_file))

return runtime

def _list_outputs(self):
outputs = self._outputs().get()
outputs['out_file'] = self._gen_filename('apm')

return outputs
35 changes: 35 additions & 0 deletions nipype/interfaces/dipy/tests/test_auto_APMQball.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
from __future__ import unicode_literals
from ..anisotropic_power import APMQball


def test_APMQball_inputs():
input_map = dict(b0_thres=dict(usedefault=True,
),
ignore_exception=dict(nohash=True,
usedefault=True,
),
in_bval=dict(mandatory=True,
),
in_bvec=dict(mandatory=True,
),
in_file=dict(mandatory=True,
),
mask_file=dict(),
out_prefix=dict(),
)
inputs = APMQball.input_spec()

for key, metadata in list(input_map.items()):
for metakey, value in list(metadata.items()):
assert getattr(inputs.traits()[key], metakey) == value


def test_APMQball_outputs():
output_map = dict(out_file=dict(),
)
outputs = APMQball.output_spec()

for key, metadata in list(output_map.items()):
for metakey, value in list(metadata.items()):
assert getattr(outputs.traits()[key], metakey) == value