diff --git a/notebooks/srr.ipynb b/notebooks/srr.ipynb index 947302c28..94bea56e0 100644 --- a/notebooks/srr.ipynb +++ b/notebooks/srr.ipynb @@ -174,7 +174,7 @@ " nlmDenoise.inputs.bids_dir = bids_dir\n", " nlmDenoise.inputs.weight = 1\n", " \n", - " \n", + " # Sans le mask le premier correct slice intensity...\n", " srtkCorrectSliceIntensity01_nlm = Node(interface=preprocess.MultipleMialsrtkCorrectSliceIntensity(),name='srtkCorrectSliceIntensity01_nlm')\n", " srtkCorrectSliceIntensity01_nlm.inputs.bids_dir = bids_dir\n", "\n", @@ -203,6 +203,23 @@ " srtkIntensityStandardization_nlm.inputs.bids_dir = bids_dir\n", " \n", " \n", + " srtkHistogramNormalization = Node(interface=preprocess.MialsrtkHistogramNormalization(),name='srtkHistogramNormalization')\n", + " srtkHistogramNormalization.inputs.bids_dir = bids_dir\n", + " \n", + " srtkHistogramNormalization_nlm = Node(interface=preprocess.MialsrtkHistogramNormalization(),name='srtkHistogramNormalization_nlm') \n", + " srtkHistogramNormalization_nlm.inputs.bids_dir = bids_dir\n", + " \n", + "\n", + " srtkImageReconstruction = Node(interface=preprocess.MialsrtkImageReconstruction(),name='srtkImageReconstruction') \n", + " srtkImageReconstruction.inputs.bids_dir = bids_dir\n", + " srtkImageReconstruction.inputs.in_roi = \"mask\"\n", + "# srtkImageReconstruction.inputs.stacksOrder = [1,2,3] \n", + "# run-1 axial\n", + "# run-2 coronal\n", + "# run-3 sagittal\n", + "\n", + " \n", + " \n", " wf.connect(bg, \"T2ws\", nlmDenoise, \"input_images\")\n", " wf.connect(bg, \"masks\", nlmDenoise, \"input_masks\")\n", " \n", @@ -219,22 +236,26 @@ " wf.connect(srtkSliceBySliceN4BiasFieldCorrection, \"output_fields\", srtkSliceBySliceCorrectBiasField, \"input_fields\")\n", " wf.connect(bg, \"masks\", srtkSliceBySliceCorrectBiasField, \"input_masks\")\n", " \n", - " \n", " wf.connect(srtkSliceBySliceCorrectBiasField, \"output_images\", srtkCorrectSliceIntensity02, \"input_images\")\n", " wf.connect(bg, \"masks\", srtkCorrectSliceIntensity02, \"input_masks\")\n", " \n", " wf.connect(srtkSliceBySliceN4BiasFieldCorrection, \"output_images\", srtkCorrectSliceIntensity02_nlm, \"input_images\")\n", " wf.connect(bg, \"masks\", srtkCorrectSliceIntensity02_nlm, \"input_masks\")\n", " \n", - " \n", - " \n", " wf.connect(srtkCorrectSliceIntensity02, \"output_images\", srtkIntensityStandardization, \"input_images\")\n", - " \n", " wf.connect(srtkCorrectSliceIntensity02_nlm, \"output_images\", srtkIntensityStandardization_nlm, \"input_images\")\n", " \n", + " wf.connect(srtkIntensityStandardization, \"output_images\", srtkHistogramNormalization, \"input_images\")\n", + " wf.connect(bg, \"masks\", srtkHistogramNormalization, \"input_masks\")\n", + " \n", + " wf.connect(srtkIntensityStandardization_nlm, \"output_images\", srtkHistogramNormalization_nlm, \"input_images\")\n", + " wf.connect(bg, \"masks\", srtkHistogramNormalization_nlm, \"input_masks\")\n", + " \n", + " \n", + " wf.connect(srtkHistogramNormalization_nlm, \"output_images\", srtkImageReconstruction, \"input_images\")\n", + " wf.connect(bg, \"masks\", srtkImageReconstruction, \"input_masks\")\n", " \n", " \n", - "\n", " return wf" ] }, @@ -250,15 +271,15 @@ "output_type": "stream", "text": [ "Ouput directory: /fetaldata/derivatives/superres-mri/sub-01\n", - "200114-18:06:15,616 nipype.interface INFO:\n", + "200115-19:07:53,248 nipype.interface INFO:\n", "\t **** Processing ****\n", - "200114-18:06:15,637 nipype.workflow INFO:\n", + "200115-19:07:53,273 nipype.workflow INFO:\n", "\t Workflow srr_preproc settings: ['check', 'execution', 'logging', 'monitoring']\n", - "200114-18:06:15,644 nipype.workflow INFO:\n", + "200115-19:07:53,281 nipype.workflow INFO:\n", "\t Running serially.\n", - "200114-18:06:15,645 nipype.workflow INFO:\n", + "200115-19:07:53,282 nipype.workflow INFO:\n", "\t [Node] Setting-up \"srr_preproc.bids_grabber\" in \"/fetaldata/derivatives/superres-mri/sub-01/srr_preproc/bids_grabber\".\n", - "200114-18:06:15,648 nipype.workflow INFO:\n", + "200115-19:07:53,285 nipype.workflow INFO:\n", "\t [Node] Running \"bids_grabber\" (\"nipype.interfaces.io.BIDSDataGrabber\")\n" ] }, @@ -266,7 +287,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "/opt/conda/envs/pymialsrtk-env/lib/python3.7/site-packages/bids/layout/layout.py:665: UserWarning: In pybids 0.9.0, the 'extensions' filter was deprecated in favor of 'extension'. The former will stop working in 0.11.0.\n", + "/opt/conda/envs/pymialsrtk-env/lib/python3.7/site-packages/bids/layout/layout.py:659: UserWarning: In pybids 0.9.0, the 'extensions' filter was deprecated in favor of 'extension'. The former will stop working in 0.11.0.\n", " warnings.warn(\"In pybids 0.9.0, the 'extensions' filter was \"\n" ] }, @@ -274,63 +295,91 @@ "name": "stdout", "output_type": "stream", "text": [ - "200114-18:06:17,87 nipype.workflow INFO:\n", + "200115-19:07:54,608 nipype.workflow INFO:\n", "\t [Node] Finished \"srr_preproc.bids_grabber\".\n", - "200114-18:06:17,88 nipype.workflow INFO:\n", + "200115-19:07:54,609 nipype.workflow INFO:\n", "\t [Node] Setting-up \"srr_preproc.srtkCorrectSliceIntensity01\" in \"/fetaldata/derivatives/superres-mri/sub-01/srr_preproc/srtkCorrectSliceIntensity01\".\n", - "200114-18:06:17,90 nipype.workflow INFO:\n", + "200115-19:07:54,612 nipype.workflow INFO:\n", "\t [Node] Cached \"srr_preproc.srtkCorrectSliceIntensity01\" - collecting precomputed outputs\n", - "200114-18:06:17,91 nipype.workflow INFO:\n", + "200115-19:07:54,612 nipype.workflow INFO:\n", "\t [Node] \"srr_preproc.srtkCorrectSliceIntensity01\" found cached.\n", - "200114-18:06:17,91 nipype.workflow INFO:\n", + "200115-19:07:54,613 nipype.workflow INFO:\n", "\t [Node] Setting-up \"srr_preproc.nlmDenoise\" in \"/fetaldata/derivatives/superres-mri/sub-01/srr_preproc/nlmDenoise\".\n", - "200114-18:06:17,94 nipype.workflow INFO:\n", + "200115-19:07:54,616 nipype.workflow INFO:\n", "\t [Node] Cached \"srr_preproc.nlmDenoise\" - collecting precomputed outputs\n", - "200114-18:06:17,95 nipype.workflow INFO:\n", + "200115-19:07:54,616 nipype.workflow INFO:\n", "\t [Node] \"srr_preproc.nlmDenoise\" found cached.\n", - "200114-18:06:17,95 nipype.workflow INFO:\n", + "200115-19:07:54,617 nipype.workflow INFO:\n", "\t [Node] Setting-up \"srr_preproc.srtkCorrectSliceIntensity01_nlm\" in \"/fetaldata/derivatives/superres-mri/sub-01/srr_preproc/srtkCorrectSliceIntensity01_nlm\".\n", - "200114-18:06:17,98 nipype.workflow INFO:\n", + "200115-19:07:54,621 nipype.workflow INFO:\n", "\t [Node] Cached \"srr_preproc.srtkCorrectSliceIntensity01_nlm\" - collecting precomputed outputs\n", - "200114-18:06:17,98 nipype.workflow INFO:\n", + "200115-19:07:54,621 nipype.workflow INFO:\n", "\t [Node] \"srr_preproc.srtkCorrectSliceIntensity01_nlm\" found cached.\n", - "200114-18:06:17,99 nipype.workflow INFO:\n", + "200115-19:07:54,622 nipype.workflow INFO:\n", "\t [Node] Setting-up \"srr_preproc.srtkSliceBySliceN4BiasFieldCorrection\" in \"/fetaldata/derivatives/superres-mri/sub-01/srr_preproc/srtkSliceBySliceN4BiasFieldCorrection\".\n", - "200114-18:06:17,102 nipype.workflow INFO:\n", + "200115-19:07:54,625 nipype.workflow INFO:\n", "\t [Node] Cached \"srr_preproc.srtkSliceBySliceN4BiasFieldCorrection\" - collecting precomputed outputs\n", - "200114-18:06:17,102 nipype.workflow INFO:\n", + "200115-19:07:54,626 nipype.workflow INFO:\n", "\t [Node] \"srr_preproc.srtkSliceBySliceN4BiasFieldCorrection\" found cached.\n", - "200114-18:06:17,103 nipype.workflow INFO:\n", + "200115-19:07:54,626 nipype.workflow INFO:\n", "\t [Node] Setting-up \"srr_preproc.srtkCorrectSliceIntensity02_nlm\" in \"/fetaldata/derivatives/superres-mri/sub-01/srr_preproc/srtkCorrectSliceIntensity02_nlm\".\n", - "200114-18:06:17,106 nipype.workflow INFO:\n", + "200115-19:07:54,629 nipype.workflow INFO:\n", "\t [Node] Cached \"srr_preproc.srtkCorrectSliceIntensity02_nlm\" - collecting precomputed outputs\n", - "200114-18:06:17,106 nipype.workflow INFO:\n", + "200115-19:07:54,630 nipype.workflow INFO:\n", "\t [Node] \"srr_preproc.srtkCorrectSliceIntensity02_nlm\" found cached.\n", - "200114-18:06:17,107 nipype.workflow INFO:\n", + "200115-19:07:54,630 nipype.workflow INFO:\n", "\t [Node] Setting-up \"srr_preproc.srtkIntensityStandardization_nlm\" in \"/fetaldata/derivatives/superres-mri/sub-01/srr_preproc/srtkIntensityStandardization_nlm\".\n", - "200114-18:06:17,110 nipype.workflow INFO:\n", + "200115-19:07:54,633 nipype.workflow INFO:\n", "\t [Node] Cached \"srr_preproc.srtkIntensityStandardization_nlm\" - collecting precomputed outputs\n", - "200114-18:06:17,111 nipype.workflow INFO:\n", + "200115-19:07:54,633 nipype.workflow INFO:\n", "\t [Node] \"srr_preproc.srtkIntensityStandardization_nlm\" found cached.\n", - "200114-18:06:17,111 nipype.workflow INFO:\n", + "200115-19:07:54,634 nipype.workflow INFO:\n", + "\t [Node] Setting-up \"srr_preproc.srtkHistogramNormalization_nlm\" in \"/fetaldata/derivatives/superres-mri/sub-01/srr_preproc/srtkHistogramNormalization_nlm\".\n", + "200115-19:07:54,637 nipype.workflow INFO:\n", + "\t [Node] Cached \"srr_preproc.srtkHistogramNormalization_nlm\" - collecting precomputed outputs\n", + "200115-19:07:54,637 nipype.workflow INFO:\n", + "\t [Node] \"srr_preproc.srtkHistogramNormalization_nlm\" found cached.\n", + "200115-19:07:54,638 nipype.workflow INFO:\n", + "\t [Node] Setting-up \"srr_preproc.srtkImageReconstruction\" in \"/fetaldata/derivatives/superres-mri/sub-01/srr_preproc/srtkImageReconstruction\".\n", + "200115-19:07:54,641 nipype.workflow INFO:\n", + "\t [Node] Running \"srtkImageReconstruction\" (\"pymialsrtk.interfaces.preprocess.MialsrtkImageReconstruction\")\n", + "input_image ['/fetaldata/derivatives/superres-mri/sub-01/srr_preproc/srtkHistogramNormalization_nlm/sub-01_run-5_T2w_nlm_csi_sliceN4corr_csi_ist_HistNorm.nii.gz', '/fetaldata/derivatives/superres-mri/sub-01/srr_preproc/srtkHistogramNormalization_nlm/sub-01_run-1_T2w_nlm_csi_sliceN4corr_csi_ist_HistNorm.nii.gz', '/fetaldata/derivatives/superres-mri/sub-01/srr_preproc/srtkHistogramNormalization_nlm/sub-01_run-2_T2w_nlm_csi_sliceN4corr_csi_ist_HistNorm.nii.gz', '/fetaldata/derivatives/superres-mri/sub-01/srr_preproc/srtkHistogramNormalization_nlm/sub-01_run-6_T2w_nlm_csi_sliceN4corr_csi_ist_HistNorm.nii.gz', '/fetaldata/derivatives/superres-mri/sub-01/srr_preproc/srtkHistogramNormalization_nlm/sub-01_run-3_T2w_nlm_csi_sliceN4corr_csi_ist_HistNorm.nii.gz', '/fetaldata/derivatives/superres-mri/sub-01/srr_preproc/srtkHistogramNormalization_nlm/sub-01_run-4_T2w_nlm_csi_sliceN4corr_csi_ist_HistNorm.nii.gz']\n", + "in roi mask\n", + "input_masks ['/fetaldata/derivatives/manual_masks/sub-01/anat/sub-01_run-1_T2w_desc-brain_mask.nii.gz', '/fetaldata/derivatives/manual_masks/sub-01/anat/sub-01_run-2_T2w_desc-brain_mask.nii.gz', '/fetaldata/derivatives/manual_masks/sub-01/anat/sub-01_run-3_T2w_desc-brain_mask.nii.gz', '/fetaldata/derivatives/manual_masks/sub-01/anat/sub-01_run-4_T2w_desc-brain_mask.nii.gz', '/fetaldata/derivatives/manual_masks/sub-01/anat/sub-01_run-5_T2w_desc-brain_mask.nii.gz', '/fetaldata/derivatives/manual_masks/sub-01/anat/sub-01_run-6_T2w_desc-brain_mask.nii.gz']\n", + "... cmd: ['mialsrtkImageReconstruction', '--mask', '--input', '/fetaldata/derivatives/superres-mri/sub-01/srr_preproc/srtkHistogramNormalization_nlm/sub-01_run-5_T2w_nlm_csi_sliceN4corr_csi_ist_HistNorm.nii.gz', '--transform', '/fetaldata/derivatives/superres-mri/sub-01/srr_preproc/srtkImageReconstruction/sub-01_run-5_T2w_nlm_csi_sliceN4corr_csi_ist_HistNorm_transf.txt', '-m', '/fetaldata/derivatives/manual_masks/sub-01/anat/sub-01_run-1_T2w_desc-brain_mask.nii.gz', '--input', '/fetaldata/derivatives/superres-mri/sub-01/srr_preproc/srtkHistogramNormalization_nlm/sub-01_run-1_T2w_nlm_csi_sliceN4corr_csi_ist_HistNorm.nii.gz', '--transform', '/fetaldata/derivatives/superres-mri/sub-01/srr_preproc/srtkImageReconstruction/sub-01_run-1_T2w_nlm_csi_sliceN4corr_csi_ist_HistNorm_transf.txt', '-m', '/fetaldata/derivatives/manual_masks/sub-01/anat/sub-01_run-2_T2w_desc-brain_mask.nii.gz', '--input', '/fetaldata/derivatives/superres-mri/sub-01/srr_preproc/srtkHistogramNormalization_nlm/sub-01_run-2_T2w_nlm_csi_sliceN4corr_csi_ist_HistNorm.nii.gz', '--transform', '/fetaldata/derivatives/superres-mri/sub-01/srr_preproc/srtkImageReconstruction/sub-01_run-2_T2w_nlm_csi_sliceN4corr_csi_ist_HistNorm_transf.txt', '-m', '/fetaldata/derivatives/manual_masks/sub-01/anat/sub-01_run-3_T2w_desc-brain_mask.nii.gz', '--input', '/fetaldata/derivatives/superres-mri/sub-01/srr_preproc/srtkHistogramNormalization_nlm/sub-01_run-6_T2w_nlm_csi_sliceN4corr_csi_ist_HistNorm.nii.gz', '--transform', '/fetaldata/derivatives/superres-mri/sub-01/srr_preproc/srtkImageReconstruction/sub-01_run-6_T2w_nlm_csi_sliceN4corr_csi_ist_HistNorm_transf.txt', '-m', '/fetaldata/derivatives/manual_masks/sub-01/anat/sub-01_run-4_T2w_desc-brain_mask.nii.gz', '--input', '/fetaldata/derivatives/superres-mri/sub-01/srr_preproc/srtkHistogramNormalization_nlm/sub-01_run-3_T2w_nlm_csi_sliceN4corr_csi_ist_HistNorm.nii.gz', '--transform', '/fetaldata/derivatives/superres-mri/sub-01/srr_preproc/srtkImageReconstruction/sub-01_run-3_T2w_nlm_csi_sliceN4corr_csi_ist_HistNorm_transf.txt', '-m', '/fetaldata/derivatives/manual_masks/sub-01/anat/sub-01_run-5_T2w_desc-brain_mask.nii.gz', '--input', '/fetaldata/derivatives/superres-mri/sub-01/srr_preproc/srtkHistogramNormalization_nlm/sub-01_run-4_T2w_nlm_csi_sliceN4corr_csi_ist_HistNorm.nii.gz', '--transform', '/fetaldata/derivatives/superres-mri/sub-01/srr_preproc/srtkImageReconstruction/sub-01_run-4_T2w_nlm_csi_sliceN4corr_csi_ist_HistNorm_transf.txt', '-m', '/fetaldata/derivatives/manual_masks/sub-01/anat/sub-01_run-6_T2w_desc-brain_mask.nii.gz', '--output', '/fetaldata/derivatives/superres-mri/sub-01/srr_preproc/srtkImageReconstruction/sub-01_run-5_T2w_nlm_csi_sliceN4corr_csi_ist_HistNorm_desc-SDI__sr.nii.gz']\n", + "200115-19:11:57,900 nipype.workflow INFO:\n", + "\t [Node] Finished \"srr_preproc.srtkImageReconstruction\".\n", + "200115-19:11:57,902 nipype.workflow INFO:\n", "\t [Node] Setting-up \"srr_preproc.srtkSliceBySliceCorrectBiasField\" in \"/fetaldata/derivatives/superres-mri/sub-01/srr_preproc/srtkSliceBySliceCorrectBiasField\".\n", - "200114-18:06:17,115 nipype.workflow INFO:\n", + "200115-19:11:57,905 nipype.workflow INFO:\n", "\t [Node] Cached \"srr_preproc.srtkSliceBySliceCorrectBiasField\" - collecting precomputed outputs\n", - "200114-18:06:17,115 nipype.workflow INFO:\n", - "\t [Node] \"srr_preproc.srtkSliceBySliceCorrectBiasField\" found cached.\n", - "200114-18:06:17,116 nipype.workflow INFO:\n", + "200115-19:11:57,905 nipype.workflow INFO:\n", + "\t [Node] \"srr_preproc.srtkSliceBySliceCorrectBiasField\" found cached.\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "200115-19:11:57,906 nipype.workflow INFO:\n", "\t [Node] Setting-up \"srr_preproc.srtkCorrectSliceIntensity02\" in \"/fetaldata/derivatives/superres-mri/sub-01/srr_preproc/srtkCorrectSliceIntensity02\".\n", - "200114-18:06:17,119 nipype.workflow INFO:\n", + "200115-19:11:57,909 nipype.workflow INFO:\n", "\t [Node] Cached \"srr_preproc.srtkCorrectSliceIntensity02\" - collecting precomputed outputs\n", - "200114-18:06:17,120 nipype.workflow INFO:\n", + "200115-19:11:57,910 nipype.workflow INFO:\n", "\t [Node] \"srr_preproc.srtkCorrectSliceIntensity02\" found cached.\n", - "200114-18:06:17,121 nipype.workflow INFO:\n", + "200115-19:11:57,911 nipype.workflow INFO:\n", "\t [Node] Setting-up \"srr_preproc.srtkIntensityStandardization\" in \"/fetaldata/derivatives/superres-mri/sub-01/srr_preproc/srtkIntensityStandardization\".\n", - "200114-18:06:17,124 nipype.workflow INFO:\n", + "200115-19:11:57,913 nipype.workflow INFO:\n", "\t [Node] Cached \"srr_preproc.srtkIntensityStandardization\" - collecting precomputed outputs\n", - "200114-18:06:17,124 nipype.workflow INFO:\n", + "200115-19:11:57,913 nipype.workflow INFO:\n", "\t [Node] \"srr_preproc.srtkIntensityStandardization\" found cached.\n", - "200114-18:06:17,262 nipype.workflow INFO:\n", + "200115-19:11:57,914 nipype.workflow INFO:\n", + "\t [Node] Setting-up \"srr_preproc.srtkHistogramNormalization\" in \"/fetaldata/derivatives/superres-mri/sub-01/srr_preproc/srtkHistogramNormalization\".\n", + "200115-19:11:57,916 nipype.workflow INFO:\n", + "\t [Node] Cached \"srr_preproc.srtkHistogramNormalization\" - collecting precomputed outputs\n", + "200115-19:11:57,917 nipype.workflow INFO:\n", + "\t [Node] \"srr_preproc.srtkHistogramNormalization\" found cached.\n", + "200115-19:11:58,75 nipype.workflow INFO:\n", "\t Generated workflow graph: /fetaldata/derivatives/superres-mri/sub-01/srr_preproc/graph.png (graph2use=hierarchical, simple_form=True).\n" ] }, @@ -354,29 +403,40 @@ { "cell_type": "code", "execution_count": 7, - "metadata": {}, + "metadata": { + "scrolled": true + }, "outputs": [ { - "name": "stdout", + "name": "stderr", "output_type": "stream", "text": [ - "200114-18:06:17,407 nipype.workflow INFO:\n", - "\t Generated workflow graph: /fetaldata/derivatives/superres-mri/sub-01/srr_preproc/graph.png (graph2use=hierarchical, simple_form=True).\n" + "Usage: nipypecli crash [OPTIONS] CRASHFILE\n", + "Try \"nipypecli crash -h\" for help.\n", + "\n", + "Error: Invalid value for \"CRASHFILE\": File \"/app/notebooks/crash-20200115-185200-root-srtkImageReconstruction-24e7a3ad-5096-41ab-b455-e616e87826d5.pklz\" does not exist.\n" ] }, { - "data": { - "text/plain": [ - "'/fetaldata/derivatives/superres-mri/sub-01/srr_preproc/graph.png'" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" + "ename": "CalledProcessError", + "evalue": "Command 'b'nipypecli crash /app/notebooks/crash-20200115-185200-root-srtkImageReconstruction-24e7a3ad-5096-41ab-b455-e616e87826d5.pklz\\n'' returned non-zero exit status 2.", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mCalledProcessError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mget_ipython\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrun_cell_magic\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'bash'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m''\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'nipypecli crash /app/notebooks/crash-20200115-185200-root-srtkImageReconstruction-24e7a3ad-5096-41ab-b455-e616e87826d5.pklz\\n'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m/opt/conda/envs/pymialsrtk-env/lib/python3.7/site-packages/IPython/core/interactiveshell.py\u001b[0m in \u001b[0;36mrun_cell_magic\u001b[0;34m(self, magic_name, line, cell)\u001b[0m\n\u001b[1;32m 2350\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbuiltin_trap\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2351\u001b[0m \u001b[0margs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mmagic_arg_s\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcell\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2352\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2353\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2354\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/envs/pymialsrtk-env/lib/python3.7/site-packages/IPython/core/magics/script.py\u001b[0m in \u001b[0;36mnamed_script_magic\u001b[0;34m(line, cell)\u001b[0m\n\u001b[1;32m 140\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 141\u001b[0m \u001b[0mline\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mscript\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 142\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshebang\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mline\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcell\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 143\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 144\u001b[0m \u001b[0;31m# write a basic docstring:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m\u001b[0m in \u001b[0;36mshebang\u001b[0;34m(self, line, cell)\u001b[0m\n", + "\u001b[0;32m/opt/conda/envs/pymialsrtk-env/lib/python3.7/site-packages/IPython/core/magic.py\u001b[0m in \u001b[0;36m\u001b[0;34m(f, *a, **k)\u001b[0m\n\u001b[1;32m 185\u001b[0m \u001b[0;31m# but it's overkill for just that one bit of state.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 186\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mmagic_deco\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marg\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 187\u001b[0;31m \u001b[0mcall\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mlambda\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 188\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 189\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mcallable\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marg\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/envs/pymialsrtk-env/lib/python3.7/site-packages/IPython/core/magics/script.py\u001b[0m in \u001b[0;36mshebang\u001b[0;34m(self, line, cell)\u001b[0m\n\u001b[1;32m 243\u001b[0m \u001b[0msys\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstderr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mflush\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 244\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mraise_error\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreturncode\u001b[0m\u001b[0;34m!=\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 245\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mCalledProcessError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreturncode\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcell\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moutput\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mout\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstderr\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0merr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 246\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 247\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m_run_script\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mp\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcell\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mto_close\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mCalledProcessError\u001b[0m: Command 'b'nipypecli crash /app/notebooks/crash-20200115-185200-root-srtkImageReconstruction-24e7a3ad-5096-41ab-b455-e616e87826d5.pklz\\n'' returned non-zero exit status 2." + ] } ], "source": [ - "m_wf.write_graph()" + "%%bash\n", + "nipypecli crash /app/notebooks/crash-20200115-185200-root-srtkImageReconstruction-24e7a3ad-5096-41ab-b455-e616e87826d5.pklz" ] }, { diff --git a/pymialsrtk/interfaces/preprocess.py b/pymialsrtk/interfaces/preprocess.py index 25a6a458f..1ac322a52 100644 --- a/pymialsrtk/interfaces/preprocess.py +++ b/pymialsrtk/interfaces/preprocess.py @@ -40,7 +40,7 @@ class BtkNLMDenoisingOutputSpec(TraitedSpec): class BtkNLMDenoising(BaseInterface): input_spec = BtkNLMDenoisingInputSpec - output_spec = BtkNLMDenoisingOutputSpec + output_spec = BtkNLMDenoisingOutputSpec def _run_interface(self, runtime): _, name, ext = split_filename(os.path.abspath(self.inputs.in_file)) @@ -290,7 +290,6 @@ class MultipleMialsrtkSliceBySliceCorrectBiasFieldInputSpec(BaseInterfaceInputSp class MultipleMialsrtkSliceBySliceCorrectBiasFieldOutputSpec(TraitedSpec): output_images = OutputMultiPath(File()) - output_fields = OutputMultiPath(File()) class MultipleMialsrtkSliceBySliceCorrectBiasField(BaseInterface): input_spec = MultipleMialsrtkSliceBySliceCorrectBiasFieldInputSpec @@ -329,19 +328,15 @@ class MialsrtkIntensityStandardization(BaseInterface): output_spec = MialsrtkIntensityStandardizationOutputSpec def _run_interface(self, runtime): - lst_in = [] - lst_out = [] + + cmd = 'mialsrtkIntensityStandardization' for input_image in self.inputs.input_images: _, name, ext = split_filename(os.path.abspath(input_image)) out_file = os.path.join(os.getcwd().replace(self.inputs.bids_dir,'/fetaldata'), ''.join((name, self.inputs.out_postfix, ext))) - - lst_in.append(input_image) - lst_out.append(out_file) + cmd = cmd + ' --input "{}" --output "{}"'.format(input_image, out_file) if self.inputs.in_max: - cmd = 'mialsrtkIntensityStandardization --input "{}" --output "{}" --max "{}"'.format(','.join(lst_in), ','.join(lst_out), self.inputs.in_max) - else: - cmd = 'mialsrtkIntensityStandardization --input "{}" --output "{}"'.format(','.join(lst_in), ','.join(lst_out)) + cmd = cmd + ' --max "{}"'.format(self.inputs.in_max) try: print('... cmd: {}'.format(cmd)) @@ -353,5 +348,180 @@ def _run_interface(self, runtime): def _list_outputs(self): outputs = self._outputs().get() - outputs['output_images'] = glob(os.path.abspath("*.nii.gz")) - return outputs \ No newline at end of file + outputs['output_images'] = glob(os.path.abspath("*_ist.nii.gz")) + return outputs + + + +# +## Histogram normalization +# + + +class MialsrtkHistogramNormalizationInputSpec(BaseInterfaceInputSpec): + bids_dir = Directory(desc='BIDS root directory',mandatory=True,exists=True) + input_images = InputMultiPath(File(desc='files to be HistNorm', mandatory = True)) + input_masks = InputMultiPath(File(desc='mask of files to be HistNorm', mandatory = False)) + out_postfix = traits.Str("_HistNorm", usedefault=True) + +class MialsrtkHistogramNormalizationOutputSpec(TraitedSpec): + output_images = OutputMultiPath(File()) + +class MialsrtkHistogramNormalization(BaseInterface): + input_spec = MialsrtkHistogramNormalizationInputSpec + output_spec = MialsrtkHistogramNormalizationOutputSpec + + def _run_interface(self, runtime): + + cmd = 'python /usr/local/bin/mialsrtkHistogramNormalization.py ' + + for in_file, in_mask in zip(self.inputs.input_images, self.inputs.input_masks): + _, name, ext = split_filename(os.path.abspath(in_file)) + out_file = os.path.join(os.getcwd().replace(self.inputs.bids_dir,'/fetaldata'), ''.join((name, self.inputs.out_postfix, ext))) + cmd = cmd + ' -i "{}" -o "{}" -m "{}" '.format(in_file, out_file, in_mask) + + try: + print('... cmd: {}'.format(cmd)) + run(self, cmd, env={}, cwd=os.path.abspath(self.inputs.bids_dir)) + except: + print('Failed') + + return runtime + + def _list_outputs(self): + outputs = self._outputs().get() + outputs['output_images'] = glob(os.path.abspath("*_HistNorm.nii.gz")) + return outputs + + + + +# +## Image Reconstruction +# + +class MialsrtkImageReconstructionInputSpec(BaseInterfaceInputSpec): + bids_dir = Directory(desc='BIDS root directory',mandatory=True,exists=True) + + in_roi = traits.Enum(None, "all", "box", "mask", mandatory = True, default='mask', usedefault=True) + # in_deblurring = traits.Bool(False, usedefault=True) + # in_reg = traits.Bool(True, usedefault=True) + # in_3d = traits.Bool(False, usedefault=True) + + # in_margin = traits.Float(usedefault=False) + # in_epsilon = traits.Float(usedefault=False) + # in_iter = traits.Int(usedefault=False) + + # in_combinedMasks = traits.Str(usedefault=False) ## ?? TODO + # # in_reference = File(desc='Reference image') # , mandatory=True) + + # in_imresampled = InputMultiPath(File(desc='')) # , mandatory = True)) + # in_imroi = InputMultiPath(File(desc='')) # , mandatory = True)) + + + input_masks = InputMultiPath(File(desc='')) # , mandatory = True)) + input_images = InputMultiPath(File(desc='')) # , mandatory = True)) + + out_sr_postfix = traits.Str("_sr", usedefault=True) + out_transf_postfix = traits.Str("_transf", usedefault=True) + stacksOrder = traits.List(mandatory=False) + + +class MialsrtkImageReconstructionOutputSpec(TraitedSpec): + output_sr = File() + output_transforms = OutputMultiPath(File(desc='SDI')) + +class MialsrtkImageReconstruction(BaseInterface): + input_spec = MialsrtkImageReconstructionInputSpec + output_spec = MialsrtkImageReconstructionOutputSpec + + def _run_interface(self, runtime): + + print("input_image", self.inputs.input_images) + print("in roi", self.inputs.in_roi) + print("input_masks", self.inputs.input_masks) + + params = [] + params.append(''.join(["--", self.inputs.in_roi])) + # if self.inputs.in_deblurring: + # params.append("--deblurring") + + # if not self.inputs.in_reg: + # params.append("--noreg") + + # if self.inputs.in_3d: + # params.append("--3D") + + # if self.inputs.in_margin: + # params.append("--margin") + # params.append(str(self.inputs.in_margin)) + + # if self.inputs.in_epsilon: + # params.append("--epsilon") + # params.append(str(self.inputs.in_epsilon)) + + # if self.inputs.in_iter: + # params.append("--iter") + # params.append(str(self.inputs.in_iter)) + + # if self.inputs.in_combinedMasks: + # params.append("--combinedMasks") + # params.append(str(self.inputs.in_combinedMasks)) + + # if self.inputs.in_reference: + # params.append("--reference") + # params.append(str(self.inputs.in_reference)) + + #if self.inputs.in_roi == "mask": + for in_file, in_mask in zip(self.inputs.input_images, self.inputs.input_masks): + _, name, ext = split_filename(os.path.abspath(in_file)) + transf_file = os.path.join(os.getcwd().replace(self.inputs.bids_dir,'/fetaldata'), ''.join((name, self.inputs.out_transf_postfix, '.txt'))) + + params.append("--input") + params.append(in_file) + + params.append("--transform") + params.append(transf_file) + + params.append("-m") + params.append(in_mask) + + _, name, ext = split_filename(os.path.abspath(self.inputs.input_images[0])) + out_file = os.path.join(os.getcwd().replace(self.inputs.bids_dir,'/fetaldata'), ''.join((name, '_desc-SDI_', self.inputs.out_sr_postfix, ext))) + params.append("--output") + params.append(out_file) + + + # if self.inputs.in_imresampled: + # for ir in self.inputs.in_imresampled: + # params.append("--ir") + # params.append(ir) + + # if self.inputs.in_imroi: + # for roi in self.inputs.in_imroi: + # params.append("--roi") + # params.append(roi) + + + + + cmd = ["mialsrtkImageReconstruction"] + cmd += params + +# cmd = ["mialsrtkImageReconstruction", "--help"] + + try: + print('... cmd: {}'.format(cmd)) + cmd = ' '.join(cmd) + run(self, cmd, env={}, cwd=os.path.abspath(self.inputs.bids_dir)) + except: + print('Failed') + return runtime + + + def _list_outputs(self): + outputs = self._outputs().get() + outputs['output_transforms'] = glob(os.path.abspath("*.txt")) + _, name, ext = split_filename(os.path.abspath(self.inputs.input_images[0])) + outputs['output_sr'] = os.path.join(os.getcwd().replace(self.inputs.bids_dir,'/fetaldata'), ''.join((name, '_desc-SDI_', self.inputs.out_sr_postfix, ext))) + return outputs diff --git a/src/IntensityStandardization/mialsrtkHistogramNormalization.py b/src/IntensityStandardization/mialsrtkHistogramNormalization.py index 13fe1897f..f11443c1d 100644 --- a/src/IntensityStandardization/mialsrtkHistogramNormalization.py +++ b/src/IntensityStandardization/mialsrtkHistogramNormalization.py @@ -45,10 +45,10 @@ def mean_nonzero(image): return mean def intensityNormalization(image,landmarks): - print 'min ='+str(landmarks['p1']) - print 'max (99.8%) ='+str(landmarks['p2']) + print('min ='+str(landmarks['p1'])) + print('max (99.8%) =',str(landmarks['p2'])) #print 'mean ='+str(landmarks['mean']) - print 'quartiles [25%,50%,75%] ='+str(landmarks['quartiles']) + print('quartiles [25%,50%,75%] ='+str(landmarks['quartiles'])) return 1 def displayHistogram(image,image_name,loffset,roffset): @@ -93,7 +93,7 @@ def trainImageLandmarks(list_landmarks): ymax=np.max(maxLR) ymax_index=maxLR.index(max(maxLR)) dS = float(ymax*(mup_L[ymax_index]+mup_R[ymax_index])) - print 'Ymax = '+str(ymax)+' at position '+str(ymax_index)+' , dS = '+str(dS)+' (=s2 when s1=0)' + print('Ymax = ', str(ymax)+' at position '+str(ymax_index)+' , dS = '+str(dS)+' (=s2 when s1=0)') return list_landmarks,dS def mapImageLandmarks(list_landmarks,s1,s2): @@ -101,13 +101,13 @@ def mapImageLandmarks(list_landmarks,s1,s2): index=0 while index