Skip to content

Commit

Permalink
ENH: Updated nipype node MialsrtkIntensityStandardization for customi…
Browse files Browse the repository at this point in the history
…zed parameters
  • Loading branch information
pdedumast committed Oct 16, 2019
1 parent 7c33b87 commit 4115548
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 26 deletions.
85 changes: 61 additions & 24 deletions notebooks/IntensityStandardization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@
"copying pymialsrtk/interfaces/preprocess.py -> build/lib/pymialsrtk/interfaces\n",
"running build_scripts\n",
"running install_lib\n",
"creating /opt/conda/envs/pymialsrtk-env/lib/python3.7/site-packages/pymialsrtk\n",
"copying build/lib/pymialsrtk/info.py -> /opt/conda/envs/pymialsrtk-env/lib/python3.7/site-packages/pymialsrtk\n",
"creating /opt/conda/envs/pymialsrtk-env/lib/python3.7/site-packages/pymialsrtk/interfaces\n",
"copying build/lib/pymialsrtk/interfaces/registration.py -> /opt/conda/envs/pymialsrtk-env/lib/python3.7/site-packages/pymialsrtk/interfaces\n",
"copying build/lib/pymialsrtk/interfaces/reconstruction.py -> /opt/conda/envs/pymialsrtk-env/lib/python3.7/site-packages/pymialsrtk/interfaces\n",
"copying build/lib/pymialsrtk/interfaces/preprocess.py -> /opt/conda/envs/pymialsrtk-env/lib/python3.7/site-packages/pymialsrtk/interfaces\n",
"copying build/lib/pymialsrtk/interfaces/__init__.py -> /opt/conda/envs/pymialsrtk-env/lib/python3.7/site-packages/pymialsrtk/interfaces\n",
"copying build/lib/pymialsrtk/interfaces/utils.py -> /opt/conda/envs/pymialsrtk-env/lib/python3.7/site-packages/pymialsrtk/interfaces\n",
"copying build/lib/pymialsrtk/__init__.py -> /opt/conda/envs/pymialsrtk-env/lib/python3.7/site-packages/pymialsrtk\n",
"creating /opt/conda/envs/pymialsrtk-env/lib/python3.7/site-packages/pymialsrtk/pipelines\n",
"copying build/lib/pymialsrtk/pipelines/__init__.py -> /opt/conda/envs/pymialsrtk-env/lib/python3.7/site-packages/pymialsrtk/pipelines\n",
"byte-compiling /opt/conda/envs/pymialsrtk-env/lib/python3.7/site-packages/pymialsrtk/info.py to info.cpython-37.pyc\n",
"byte-compiling /opt/conda/envs/pymialsrtk-env/lib/python3.7/site-packages/pymialsrtk/interfaces/registration.py to registration.cpython-37.pyc\n",
Expand All @@ -40,6 +37,7 @@
"copying build/scripts-3.7/superresolution -> /opt/conda/envs/pymialsrtk-env/bin\n",
"changing mode of /opt/conda/envs/pymialsrtk-env/bin/superresolution to 755\n",
"running install_egg_info\n",
"Removing /opt/conda/envs/pymialsrtk-env/lib/python3.7/site-packages/pymialsrtk-2.0.0_beta_20190906-py3.7.egg-info\n",
"Writing /opt/conda/envs/pymialsrtk-env/lib/python3.7/site-packages/pymialsrtk-2.0.0_beta_20190906-py3.7.egg-info\n"
]
}
Expand All @@ -55,21 +53,23 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"metadata": {
"scrolled": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Check for /fetaldata/derivatives/mialsrtk/dataset_description.json\n",
"File /fetaldata/derivatives/mialsrtk/dataset_description.json was created\n",
"191009-10:55:23,81 nipype.workflow INFO:\n",
"191016-16:48:13,285 nipype.workflow INFO:\n",
"\t Workflow ist settings: ['check', 'execution', 'logging', 'monitoring']\n",
"191009-10:55:23,84 nipype.workflow INFO:\n",
"191016-16:48:13,288 nipype.workflow INFO:\n",
"\t Running serially.\n",
"191009-10:55:23,84 nipype.workflow INFO:\n",
"191016-16:48:13,288 nipype.workflow INFO:\n",
"\t [Node] Setting-up \"ist.bids_grabber\" in \"/fetaldata/derivatives/mialsrtk/sub-01/nipype/ist/bids_grabber\".\n",
"191009-10:55:23,87 nipype.workflow INFO:\n",
"191016-16:48:13,291 nipype.workflow INFO:\n",
"\t [Node] Running \"bids_grabber\" (\"nipype.interfaces.io.BIDSDataGrabber\")\n"
]
},
Expand All @@ -85,26 +85,44 @@
"name": "stdout",
"output_type": "stream",
"text": [
"191009-10:55:24,16 nipype.workflow INFO:\n",
"191016-16:48:14,258 nipype.workflow INFO:\n",
"\t [Node] Finished \"ist.bids_grabber\".\n",
"191009-10:55:24,17 nipype.workflow INFO:\n",
"\t [Node] Setting-up \"ist.ist\" in \"/fetaldata/derivatives/mialsrtk/sub-01/nipype/ist/ist\".\n",
"191009-10:55:24,19 nipype.workflow INFO:\n",
"\t [Node] Running \"ist\" (\"pymialsrtk.interfaces.preprocess.MultipleMialsrtkIntensityStandardization\")\n",
"191016-16:48:14,258 nipype.workflow INFO:\n",
"\t [Node] Setting-up \"ist.ist_max\" in \"/fetaldata/derivatives/mialsrtk/sub-01/nipype/ist/ist_max\".\n",
"191016-16:48:14,261 nipype.workflow INFO:\n",
"\t [Node] Running \"ist_max\" (\"pymialsrtk.interfaces.preprocess.MultipleMialsrtkIntensityStandardization\")\n",
"input_image /fetaldata/sub-01/anat/sub-01_run-1_T2w.nii.gz\n",
"... cmd: mialsrtkIntensityStandardization --input \"/fetaldata/sub-01/anat/sub-01_run-1_T2w.nii.gz\" --output \"/fetaldata/derivatives/mialsrtk/sub-01/nipype/ist/ist_max/sub-01_run-1_T2w_ist.nii.gz\" --max \"271.0\"\n",
"input_image /fetaldata/sub-01/anat/sub-01_run-2_T2w.nii.gz\n",
"... cmd: mialsrtkIntensityStandardization --input \"/fetaldata/sub-01/anat/sub-01_run-2_T2w.nii.gz\" --output \"/fetaldata/derivatives/mialsrtk/sub-01/nipype/ist/ist_max/sub-01_run-2_T2w_ist.nii.gz\" --max \"271.0\"\n",
"input_image /fetaldata/sub-01/anat/sub-01_run-3_T2w.nii.gz\n",
"... cmd: mialsrtkIntensityStandardization --input \"/fetaldata/sub-01/anat/sub-01_run-3_T2w.nii.gz\" --output \"/fetaldata/derivatives/mialsrtk/sub-01/nipype/ist/ist_max/sub-01_run-3_T2w_ist.nii.gz\" --max \"271.0\"\n",
"input_image /fetaldata/sub-01/anat/sub-01_run-4_T2w.nii.gz\n",
"... cmd: mialsrtkIntensityStandardization --input \"/fetaldata/sub-01/anat/sub-01_run-4_T2w.nii.gz\" --output \"/fetaldata/derivatives/mialsrtk/sub-01/nipype/ist/ist_max/sub-01_run-4_T2w_ist.nii.gz\" --max \"271.0\"\n",
"input_image /fetaldata/sub-01/anat/sub-01_run-5_T2w.nii.gz\n",
"... cmd: mialsrtkIntensityStandardization --input \"/fetaldata/sub-01/anat/sub-01_run-5_T2w.nii.gz\" --output \"/fetaldata/derivatives/mialsrtk/sub-01/nipype/ist/ist_max/sub-01_run-5_T2w_ist.nii.gz\" --max \"271.0\"\n",
"input_image /fetaldata/sub-01/anat/sub-01_run-6_T2w.nii.gz\n",
"... cmd: mialsrtkIntensityStandardization --input \"/fetaldata/sub-01/anat/sub-01_run-6_T2w.nii.gz\" --output \"/fetaldata/derivatives/mialsrtk/sub-01/nipype/ist/ist_max/sub-01_run-6_T2w_ist.nii.gz\" --max \"271.0\"\n",
"191016-16:48:16,854 nipype.workflow INFO:\n",
"\t [Node] Finished \"ist.ist_max\".\n",
"191016-16:48:16,855 nipype.workflow INFO:\n",
"\t [Node] Setting-up \"ist.ist_nomax\" in \"/fetaldata/derivatives/mialsrtk/sub-01/nipype/ist/ist_nomax\".\n",
"191016-16:48:16,857 nipype.workflow INFO:\n",
"\t [Node] Running \"ist_nomax\" (\"pymialsrtk.interfaces.preprocess.MultipleMialsrtkIntensityStandardization\")\n",
"input_image /fetaldata/sub-01/anat/sub-01_run-1_T2w.nii.gz\n",
"... cmd: mialsrtkIntensityStandardization --input \"/fetaldata/sub-01/anat/sub-01_run-1_T2w.nii.gz\" --output \"/fetaldata/derivatives/mialsrtk/sub-01/nipype/ist/ist/sub-01_run-1_T2w_ist.nii.gz\"\n",
"... cmd: mialsrtkIntensityStandardization --input \"/fetaldata/sub-01/anat/sub-01_run-1_T2w.nii.gz\" --output \"/fetaldata/derivatives/mialsrtk/sub-01/nipype/ist/ist_nomax/sub-01_run-1_T2w_ist.nii.gz\"\n",
"input_image /fetaldata/sub-01/anat/sub-01_run-2_T2w.nii.gz\n",
"... cmd: mialsrtkIntensityStandardization --input \"/fetaldata/sub-01/anat/sub-01_run-2_T2w.nii.gz\" --output \"/fetaldata/derivatives/mialsrtk/sub-01/nipype/ist/ist/sub-01_run-2_T2w_ist.nii.gz\"\n",
"... cmd: mialsrtkIntensityStandardization --input \"/fetaldata/sub-01/anat/sub-01_run-2_T2w.nii.gz\" --output \"/fetaldata/derivatives/mialsrtk/sub-01/nipype/ist/ist_nomax/sub-01_run-2_T2w_ist.nii.gz\"\n",
"input_image /fetaldata/sub-01/anat/sub-01_run-3_T2w.nii.gz\n",
"... cmd: mialsrtkIntensityStandardization --input \"/fetaldata/sub-01/anat/sub-01_run-3_T2w.nii.gz\" --output \"/fetaldata/derivatives/mialsrtk/sub-01/nipype/ist/ist/sub-01_run-3_T2w_ist.nii.gz\"\n",
"... cmd: mialsrtkIntensityStandardization --input \"/fetaldata/sub-01/anat/sub-01_run-3_T2w.nii.gz\" --output \"/fetaldata/derivatives/mialsrtk/sub-01/nipype/ist/ist_nomax/sub-01_run-3_T2w_ist.nii.gz\"\n",
"input_image /fetaldata/sub-01/anat/sub-01_run-4_T2w.nii.gz\n",
"... cmd: mialsrtkIntensityStandardization --input \"/fetaldata/sub-01/anat/sub-01_run-4_T2w.nii.gz\" --output \"/fetaldata/derivatives/mialsrtk/sub-01/nipype/ist/ist/sub-01_run-4_T2w_ist.nii.gz\"\n",
"... cmd: mialsrtkIntensityStandardization --input \"/fetaldata/sub-01/anat/sub-01_run-4_T2w.nii.gz\" --output \"/fetaldata/derivatives/mialsrtk/sub-01/nipype/ist/ist_nomax/sub-01_run-4_T2w_ist.nii.gz\"\n",
"input_image /fetaldata/sub-01/anat/sub-01_run-5_T2w.nii.gz\n",
"... cmd: mialsrtkIntensityStandardization --input \"/fetaldata/sub-01/anat/sub-01_run-5_T2w.nii.gz\" --output \"/fetaldata/derivatives/mialsrtk/sub-01/nipype/ist/ist/sub-01_run-5_T2w_ist.nii.gz\"\n",
"... cmd: mialsrtkIntensityStandardization --input \"/fetaldata/sub-01/anat/sub-01_run-5_T2w.nii.gz\" --output \"/fetaldata/derivatives/mialsrtk/sub-01/nipype/ist/ist_nomax/sub-01_run-5_T2w_ist.nii.gz\"\n",
"input_image /fetaldata/sub-01/anat/sub-01_run-6_T2w.nii.gz\n",
"... cmd: mialsrtkIntensityStandardization --input \"/fetaldata/sub-01/anat/sub-01_run-6_T2w.nii.gz\" --output \"/fetaldata/derivatives/mialsrtk/sub-01/nipype/ist/ist/sub-01_run-6_T2w_ist.nii.gz\"\n",
"191009-10:55:26,579 nipype.workflow INFO:\n",
"\t [Node] Finished \"ist.ist\".\n"
"... cmd: mialsrtkIntensityStandardization --input \"/fetaldata/sub-01/anat/sub-01_run-6_T2w.nii.gz\" --output \"/fetaldata/derivatives/mialsrtk/sub-01/nipype/ist/ist_nomax/sub-01_run-6_T2w_ist.nii.gz\"\n",
"191016-16:48:19,428 nipype.workflow INFO:\n",
"\t [Node] Finished \"ist.ist_nomax\".\n"
]
}
],
Expand Down Expand Up @@ -160,13 +178,32 @@
"bg.inputs.raise_on_empty = False\n",
"bg.inputs.output_query = {'T2ws': dict(suffix='T2w',datatype='anat',extensions=[\".nii\",\".nii.gz\"])}\n",
"\n",
"ist = Node(interface=preprocess.MultipleMialsrtkIntensityStandardization(),name='ist')\n",
"ist.inputs.bids_dir = bids_dir\n",
"\n",
"# \n",
"## Not specified maximum value\n",
"ist_nomax = Node(interface=preprocess.MultipleMialsrtkIntensityStandardization(),name='ist_nomax')\n",
"ist_nomax.inputs.bids_dir = bids_dir\n",
" \n",
"wf.connect(bg, \"T2ws\", ist, \"input_images\")\n",
"wf.connect(bg, \"T2ws\", ist_nomax, \"input_images\")\n",
"\n",
"# \n",
"## Specified maximum value\n",
"ist_max = Node(interface=preprocess.MultipleMialsrtkIntensityStandardization(),name='ist_max')\n",
"ist_max.inputs.bids_dir = bids_dir\n",
"ist_max.inputs.in_max = 271.0\n",
" \n",
"wf.connect(bg, \"T2ws\", ist_max, \"input_images\")\n",
"\n",
"\n",
"res = wf.run()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
13 changes: 11 additions & 2 deletions pymialsrtk/interfaces/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ class MialsrtkIntensityStandardizationInputSpec(BaseInterfaceInputSpec):
bids_dir = Directory(desc='BIDS root directory',mandatory=True,exists=True)
in_file = File(desc='Input image',mandatory=True)
out_postfix = traits.Str("_ist", usedefault=True)
in_max = traits.Float(usedefault=False)

class MialsrtkIntensityStandardizationOutputSpec(TraitedSpec):
out_file = File(desc='Intensities standardized')
Expand All @@ -260,7 +261,10 @@ def _run_interface(self, runtime):
_, name, ext = split_filename(os.path.abspath(self.inputs.in_file))
out_file = os.path.join(os.getcwd().replace(self.inputs.bids_dir,'/fetaldata'), ''.join((name, self.inputs.out_postfix, ext)))

cmd = 'mialsrtkIntensityStandardization --input "{}" --output "{}"'.format(self.inputs.in_file, out_file)
if self.inputs.in_max:
cmd = 'mialsrtkIntensityStandardization --input "{}" --output "{}" --max "{}"'.format(self.inputs.in_file, out_file,self.inputs.in_max)
else:
cmd = 'mialsrtkIntensityStandardization --input "{}" --output "{}"'.format(self.inputs.in_file, out_file)

try:
print('... cmd: {}'.format(cmd))
Expand All @@ -281,6 +285,7 @@ class MultipleMialsrtkIntensityStandardizationInputSpec(BaseInterfaceInputSpec):
bids_dir = Directory(desc='BIDS root directory',mandatory=True,exists=True)
input_images = InputMultiPath(File(desc='files to be corrected for intensity', mandatory = True))
out_postfix = traits.Str("_ist", usedefault=True)
in_max = traits.Float(usedefault=False)

class MultipleMialsrtkIntensityStandardizationOutputSpec(TraitedSpec):
output_images = OutputMultiPath(File())
Expand All @@ -292,7 +297,11 @@ class MultipleMialsrtkIntensityStandardization(BaseInterface):
def _run_interface(self, runtime):
for input_image in self.inputs.input_images:
print("input_image", input_image)
ax = MialsrtkIntensityStandardization(bids_dir = self.inputs.bids_dir, in_file = input_image, out_postfix=self.inputs.out_postfix)

if self.inputs.in_max:
ax = MialsrtkIntensityStandardization(bids_dir = self.inputs.bids_dir, in_file = input_image, out_postfix=self.inputs.out_postfix, in_max=self.inputs.in_max)
else:
ax = MialsrtkIntensityStandardization(bids_dir = self.inputs.bids_dir, in_file = input_image, out_postfix=self.inputs.out_postfix)
ax.run()
return runtime

Expand Down

0 comments on commit 4115548

Please sign in to comment.