-
Notifications
You must be signed in to change notification settings - Fork 301
ENH: initial support for duecredit #608
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
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c8f8301
ENH: initial duecredit support
yarikoptic 4bed2e0
Merge remote-tracking branch 'upstream/master' into enh-duecredit
effigies 4ecea8a
DUE: Add 1.0.0-rc5 Zenodo
effigies a1ed499
RF/DUE: Promote phdiff2fmap to interface
effigies 492c867
Merge pull request #1 from effigies/enh-duecredit
yarikoptic de23a46
BF: forgotten import of Doi (thanks @effigies)
yarikoptic eaa7753
Merge branch 'master' into enh-duecredit
effigies 66d14ef
Merge branch 'master' into enh-duecredit
effigies 8050930
FIX: Imports and typos
effigies File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# emacs: at the end of the file | ||
# ex: set sts=4 ts=4 sw=4 et: | ||
# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### # | ||
""" | ||
|
||
Stub file for a guaranteed safe import of duecredit constructs: if duecredit | ||
is not available. | ||
|
||
To use it, place it into your project codebase to be imported, e.g. copy as | ||
|
||
cp stub.py /path/tomodule/module/due.py | ||
|
||
Note that it might be better to avoid naming it duecredit.py to avoid shadowing | ||
installed duecredit. | ||
|
||
Then use in your code as | ||
|
||
from .due import due, Doi, BibTeX | ||
|
||
See https://github.com/duecredit/duecredit/blob/master/README.md for examples. | ||
|
||
Origin: Originally a part of the duecredit | ||
Copyright: 2015-2016 DueCredit developers | ||
License: BSD-2 | ||
""" | ||
|
||
__version__ = '0.0.5' | ||
|
||
|
||
class InactiveDueCreditCollector(object): | ||
"""Just a stub at the Collector which would not do anything""" | ||
def _donothing(self, *args, **kwargs): | ||
"""Perform no good and no bad""" | ||
pass | ||
|
||
def dcite(self, *args, **kwargs): | ||
"""If I could cite I would""" | ||
def nondecorating_decorator(func): | ||
return func | ||
return nondecorating_decorator | ||
|
||
cite = load = add = _donothing | ||
|
||
def __repr__(self): | ||
return self.__class__.__name__ + '()' | ||
|
||
|
||
def _donothing_func(*args, **kwargs): | ||
"""Perform no good and no bad""" | ||
pass | ||
|
||
|
||
try: | ||
from duecredit import due, BibTeX, Doi, Url | ||
if 'due' in locals() and not hasattr(due, 'cite'): | ||
raise RuntimeError( | ||
"Imported due lacks .cite. DueCredit is now disabled") | ||
except Exception as e: | ||
if type(e).__name__ != 'ImportError': | ||
import logging | ||
logging.getLogger("duecredit").error( | ||
"Failed to import duecredit due to %s" % str(e)) | ||
# Initiate due stub | ||
due = InactiveDueCreditCollector() | ||
BibTeX = Doi = Url = _donothing_func | ||
|
||
# Emacs mode definitions | ||
# Local Variables: | ||
# mode: python | ||
# py-indent-offset: 4 | ||
# tab-width: 4 | ||
# indent-tabs-mode: nil | ||
# End: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
from niworkflows.nipype.interfaces.base import ( | ||
BaseInterfaceInputSpec, TraitedSpec, File, isdefined, traits, | ||
SimpleInterface) | ||
from ..due import Doi | ||
|
||
LOGGER = logging.getLogger('interface') | ||
|
||
|
@@ -127,6 +128,50 @@ def _run_interface(self, runtime): | |
return runtime | ||
|
||
|
||
class PhaseDiff2FieldmapInputSpec(BaseInterfaceInputSpec): | ||
in_file = traits.File(exists=True, mandatory=True, desc='Input phdiff file') | ||
delta_te = traits.Float(mandatory=True, desc='Echo time (TE) difference') | ||
|
||
|
||
class PhaseDiff2FieldmapOutputSpec(TraitedSpec): | ||
out_file = traits.File(exists=True) | ||
|
||
|
||
class PhaseDiff2Fieldmap(SimpleInterface): | ||
r""" | ||
Converts the input phase-difference map into a fieldmap in Hz, | ||
using the eq. (1) of [Hutton2002]_: | ||
|
||
.. math:: | ||
|
||
\Delta B_0 (\text{T}^{-1}) = \frac{\Delta \Theta}{2\pi\gamma \Delta\text{TE}} | ||
|
||
|
||
In this case, we do not take into account the gyromagnetic ratio of the | ||
proton (:math:`\gamma`), since it will be applied inside TOPUP: | ||
|
||
.. math:: | ||
|
||
\Delta B_0 (\text{Hz}) = \frac{\Delta \Theta}{2\pi \Delta\text{TE}} | ||
|
||
|
||
.. [Hutton2002] Hutton et al., Image Distortion Correction in fMRI: A Quantitative | ||
Evaluation, NeuroImage 16(1):217-240, 2002. doi:`10.1006/nimg.2001.1054 | ||
<http://dx.doi.org/10.1006/nimg.2001.1054>`_. | ||
|
||
""" | ||
input_spec = PhaseDiff2FieldmapInputSpec | ||
output_spec = PhaseDiff2FieldmapOutputSpec | ||
references_ = [{ | ||
'entry': Doi('10.1006/nimg.2001.1054'), | ||
'description': "Conversion of the input phase-difference map into a fieldmap in Hz", | ||
'tags': ['edu']}] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this tag mean? |
||
|
||
def _run_interface(self, runtime): | ||
self._results['out_file'] = phdiff2fmap(self.inputs.in_file, self.inputs.delta_te) | ||
return runtime | ||
|
||
|
||
def _despike2d(data, thres, neigh=None): | ||
""" | ||
despiking as done in FSL fugue | ||
|
@@ -181,3 +226,50 @@ def _unwrap(fmap_data, mag_file, mask=None): | |
|
||
unwrapped = nb.load(res.outputs.unwrapped_phase_file).get_data() * (fmapmax / pi) | ||
return unwrapped | ||
|
||
|
||
# The phdiff2fmap interface is equivalent to: | ||
# rad2rsec (using rads2radsec from nipype.workflows.dmri.fsl.utils) | ||
# pre_fugue = pe.Node(fsl.FUGUE(save_fmap=True), name='ComputeFieldmapFUGUE') | ||
# rsec2hz (divide by 2pi) | ||
def phdiff2fmap(in_file, delta_te, out_file=None): | ||
r""" | ||
Converts the input phase-difference map into a fieldmap in Hz, | ||
using the eq. (1) of [Hutton2002]_: | ||
|
||
.. math:: | ||
|
||
\Delta B_0 (\text{T}^{-1}) = \frac{\Delta \Theta}{2\pi\gamma \Delta\text{TE}} | ||
|
||
|
||
In this case, we do not take into account the gyromagnetic ratio of the | ||
proton (:math:`\gamma`), since it will be applied inside TOPUP: | ||
|
||
.. math:: | ||
|
||
\Delta B_0 (\text{Hz}) = \frac{\Delta \Theta}{2\pi \Delta\text{TE}} | ||
|
||
|
||
.. [Hutton2002] Hutton et al., Image Distortion Correction in fMRI: A Quantitative | ||
Evaluation, NeuroImage 16(1):217-240, 2002. doi:`10.1006/nimg.2001.1054 | ||
<http://dx.doi.org/10.1006/nimg.2001.1054>`_. | ||
|
||
""" | ||
import numpy as np | ||
import nibabel as nb | ||
import os.path as op | ||
import math | ||
|
||
# GYROMAG_RATIO_H_PROTON_MHZ = 42.576 | ||
|
||
if out_file is None: | ||
fname, fext = op.splitext(op.basename(in_file)) | ||
if fext == '.gz': | ||
fname, _ = op.splitext(fname) | ||
out_file = op.abspath('./%s_fmap.nii.gz' % fname) | ||
|
||
image = nb.load(in_file) | ||
data = (image.get_data().astype(np.float32) / (2. * math.pi * delta_te)) | ||
|
||
nb.Nifti1Image(data, image.affine, image.header).to_filename(out_file) | ||
return out_file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the status regarding this? There is a DOI for the Zenodo entry now, right?