Skip to content

Commit

Permalink
bump verison, merge pull request #17 from AMYPAD/dcm2nii
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Dec 1, 2021
2 parents a408348 + 3da8ac7 commit 152a9a8
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
6 changes: 4 additions & 2 deletions README.rst
Expand Up @@ -9,13 +9,15 @@ Amyloid imaging to prevent Alzheimer's Disease.
Install
-------

Choose one of the following:
Requires Python 3.6 or greater. Choose one of the following:

.. code:: sh
pip install amypet # command line interface (CLI) version
pip install amypet # command line interface (CLI) version
pip install amypet[gui] # CLI and graphical user interface (GUI) version
For certain functionality (image trimming & resampling, DICOM to NIfTI converters) it may be required to also `pip install nimpa`.


Usage
-----
Expand Down
27 changes: 27 additions & 0 deletions amypet/dcm2nii.py
@@ -0,0 +1,27 @@
"""Convert DICOM folder to a NIfTI file
Usage:
dcm2nii [options] <dcmpth>
Arguments:
<dcmpth> : Input folder containing DICOM files [default: DirChooser]
Options:
--fcomment COMMENT : Prefix to add to outputs
--timestamp : Whether to include a timestamp in the output filename
"""
import logging
from pathlib import Path

from niftypet import nimpa

log = logging.getLogger(__name__)


def run(dcmpth, fcomment="converted-from-DICOM_", timestamp=True):
dcmpth = Path(dcmpth)
assert dcmpth.is_dir()
log.info("convert")
res = nimpa.dcm2nii(dcmpth, fprefix=fcomment, timestamp=timestamp)
log.debug("output file:%s", res)
return res
5 changes: 4 additions & 1 deletion amypet/gui.py
Expand Up @@ -249,7 +249,7 @@ def main(args=None, gui_mode=True):
import niftypad.api
import niftypad.models

from amypet import centiloid, imscroll, imtrimup
from amypet import centiloid, dcm2nii, imscroll, imtrimup

parser = fix_subparser(MyParser(prog=None if gui_mode else "amypet"), gui_mode=gui_mode)
sub_kwargs = {}
Expand All @@ -273,6 +273,9 @@ def argparser(prog, description=None, epilog=None, formatter_class=None):
Func(imscroll.run, imscroll.__doc__, version=niftypad.__version__,
python_deps=["miutil[nii,plot]", "tqdm"], argparser=argparser)

Func(dcm2nii.run, dcm2nii.__doc__, version=niftypad.__version__, python_deps=["nimpa"],
argparser=argparser)

Func(imtrimup.run, imtrimup.__doc__, version=niftypad.__version__, python_deps=["nimpa"],
argparser=argparser)

Expand Down
14 changes: 14 additions & 0 deletions tests/test_dcm2nii.py
@@ -0,0 +1,14 @@
from pathlib import Path

import pytest


@pytest.mark.timeout(30 * 60) # 30m
def test_dcm2nii(datain):
dcmpth = Path(datain['mumapDCM'])
assert not list(dcmpth.glob('test_dcm2nii_*.nii*'))
dcm2nii = pytest.importorskip("amypet.dcm2nii")
dcm2nii.run(datain['mumapDCM'], fcomment="test_dcm2nii_")
assert list(dcmpth.glob('test_dcm2nii_*.nii*'))
for f in dcmpth.glob('test_dcm2nii_*.nii*'):
f.unlink()

0 comments on commit 152a9a8

Please sign in to comment.