|
3 | 3 | "_draft": {
|
4 | 4 | "nbviewer_url": "gisting : nipype.ipynb\r\n"
|
5 | 5 | },
|
6 |
| - "name": "nipype" |
| 6 | + "name": "nipype_tutorial" |
7 | 7 | },
|
8 | 8 | "nbformat": 3,
|
9 | 9 | "nbformat_minor": 0,
|
|
440 | 440 | "# Some preliminaries\n",
|
441 | 441 | "import os\n",
|
442 | 442 | "cwd = os.getcwd()\n",
|
443 |
| - "tutorial_dir = '/software/temp/nipype-tutorial/mgh/'\n", |
| 443 | + "tutorial_dir = '/software/temp/nipype-tutorial/ohbm/'\n", |
444 | 444 | "if not os.path.exists(tutorial_dir):\n",
|
445 | 445 | " os.mkdir(tutorial_dir)\n",
|
446 | 446 | "os.chdir(tutorial_dir)"
|
|
457 | 457 | "cell_type": "code",
|
458 | 458 | "collapsed": false,
|
459 | 459 | "input": [
|
460 |
| - "if not os.path.exists('ds107_raw_0.tgz'):\n", |
461 |
| - " os.system('curl -O https://openfmri.org/system/files/ds107_raw_0.tgz')" |
462 |
| - ], |
463 |
| - "language": "python", |
464 |
| - "metadata": {}, |
465 |
| - "outputs": [] |
466 |
| - }, |
467 |
| - { |
468 |
| - "cell_type": "code", |
469 |
| - "collapsed": false, |
470 |
| - "input": [ |
471 |
| - "subjects_dir = '/software/temp/nipype-tutorial/mgh/openfmri/ds107/'" |
| 460 | + "import urllib\n", |
| 461 | + "required_files = ['ds107/sub001/BOLD/task001_run001/bold.nii.gz',\n", |
| 462 | + " 'ds107/sub001/BOLD/task001_run002/bold.nii.gz',\n", |
| 463 | + " 'ds107/sub001/anatomy/highres001.nii.gz',\n", |
| 464 | + " 'ds107/sub044/BOLD/task001_run001/bold.nii.gz',\n", |
| 465 | + " 'ds107/sub044/BOLD/task001_run002/bold.nii.gz',\n", |
| 466 | + " 'ds107/sub044/anatomy/highres001.nii.gz'\n", |
| 467 | + " ]\n", |
| 468 | + "base_url = 'http://openfmri.aws.amazon.com.s3.amazonaws.com/'\n", |
| 469 | + "for filepath in required_files:\n", |
| 470 | + " file_location = os.path.join(tutorial_dir, filepath)\n", |
| 471 | + " if not os.path.exists(file_location):\n", |
| 472 | + " print('Retrieving: ' + file_location)\n", |
| 473 | + " os.makedirs(os.path.dirname(file_location))\n", |
| 474 | + " urllib.urlretrieve(base_url + filepath, file_location)" |
472 | 475 | ],
|
473 | 476 | "language": "python",
|
474 | 477 | "metadata": {},
|
|
1485 | 1488 | "cell_type": "code",
|
1486 | 1489 | "collapsed": false,
|
1487 | 1490 | "input": [
|
1488 |
| - "from nipype.workflows.smri.freesurfer.utils import create_getmask_flow\n", |
| 1491 | + "config.set_default_config()\n", |
| 1492 | + "logging.update_logging(config)" |
| 1493 | + ], |
| 1494 | + "language": "python", |
| 1495 | + "metadata": {}, |
| 1496 | + "outputs": [] |
| 1497 | + }, |
| 1498 | + { |
| 1499 | + "cell_type": "code", |
| 1500 | + "collapsed": false, |
| 1501 | + "input": [ |
| 1502 | + "from nipype.workflows.fmri.fsl.preprocess import create_susan_smooth\n", |
1489 | 1503 | "\n",
|
1490 |
| - "getmask = create_getmask_flow()\n", |
1491 |
| - "getmask.inputs.inputspec.source_file = 'mean.nii'\n", |
1492 |
| - "getmask.inputs.inputspec.subject_id = 'sub001'\n", |
1493 |
| - "getmask.inputs.inputspec.subjects_dir = subjects_dir\n", |
1494 |
| - "getmask.inputs.inputspec.contrast_type = 't2'\n", |
| 1504 | + "smooth = create_susan_smooth()\n", |
| 1505 | + "smooth.inputs.inputnode.in_files = opap('output/realigned/_subject_id_sub044/rbold_out.nii')\n", |
| 1506 | + "smooth.inputs.inputnode.fwhm = 5\n", |
| 1507 | + "smooth.inputs.inputnode.mask_file = 'mask.nii'\n", |
1495 | 1508 | "\n",
|
1496 |
| - "getmask.run() # Will error because mean.nii does not exist" |
| 1509 | + "smooth.run() # Will error because mask.nii does not exist" |
1497 | 1510 | ],
|
1498 | 1511 | "language": "python",
|
1499 | 1512 | "metadata": {},
|
|
1503 | 1516 | "cell_type": "code",
|
1504 | 1517 | "collapsed": false,
|
1505 | 1518 | "input": [
|
1506 |
| - "from nipype.interfaces.fsl.maths import MeanImage\n", |
| 1519 | + "from nipype.interfaces.fsl import BET, MeanImage, ImageMaths\n", |
1507 | 1520 | "from nipype.pipeline.engine import Node\n",
|
1508 | 1521 | "\n",
|
1509 |
| - "mi = Node(MeanImage(), name='mean_image')\n", |
1510 |
| - "mi.inputs.in_file = opap('ds107/sub001/BOLD/task001_run001/bold.nii.gz')\n", |
| 1522 | + "\n", |
| 1523 | + "remove_nan = Node(ImageMaths(op_string= '-nan'), name='nanremove')\n", |
| 1524 | + "remove_nan.inputs.in_file = opap('output/realigned/_subject_id_sub044/rbold_out.nii')\n", |
| 1525 | + "\n", |
| 1526 | + "mi = Node(MeanImage(), name='mean')\n", |
| 1527 | + "\n", |
| 1528 | + "mask = Node(BET(mask=True), name='mask')\n", |
1511 | 1529 | "\n",
|
1512 | 1530 | "wf = Workflow('reuse')\n",
|
1513 | 1531 | "wf.base_dir = opap('.')\n",
|
1514 |
| - "wf.connect(mi, 'out_file', getmask, 'inputspec.source_file')\n", |
| 1532 | + "wf.connect(remove_nan, 'out_file', mi, 'in_file')\n", |
| 1533 | + "wf.connect(mi, 'out_file', mask, 'in_file')\n", |
| 1534 | + "wf.connect(mask, 'out_file', smooth, 'inputnode.mask_file')\n", |
| 1535 | + "wf.connect(remove_nan, 'out_file', smooth, 'inputnode.in_files')\n", |
1515 | 1536 | "\n",
|
1516 |
| - "config.set_default_config()\n", |
1517 |
| - "logging.update_logging(config)\n", |
1518 | 1537 | "wf.run()"
|
1519 | 1538 | ],
|
1520 | 1539 | "language": "python",
|
|
1536 | 1555 | "cell_type": "code",
|
1537 | 1556 | "collapsed": false,
|
1538 | 1557 | "input": [
|
1539 |
| - "print(getmask.list_node_names())\n", |
1540 |
| - "bin_node = getmask.get_node('threshold2')\n", |
1541 |
| - "bin_node.inputs.dilate = 3\n", |
1542 |
| - "bin_node.inputs.erode = 2" |
| 1558 | + "print(smooth.list_node_names())\n", |
| 1559 | + "\n", |
| 1560 | + "median = smooth.get_node('median')\n", |
| 1561 | + "median.inputs.op_string = '-k %s -p 60'" |
1543 | 1562 | ],
|
1544 | 1563 | "language": "python",
|
1545 | 1564 | "metadata": {
|
|
0 commit comments