Skip to content

Commit

Permalink
Merge branch 'master' into move_user_docs
Browse files Browse the repository at this point in the history
  • Loading branch information
miykael authored May 8, 2018
2 parents 88fb16f + 42a6e9f commit 2cf5af2
Show file tree
Hide file tree
Showing 7 changed files with 292 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# pull request on our GitHub repository:
# https://github.com/kaczmarj/neurodocker
#
# Timestamp: 2018-05-07 20:43:11
# Timestamp: 2018-05-07 20:43:57

FROM neurodebian:stretch-non-free

Expand Down Expand Up @@ -289,6 +289,6 @@ RUN echo '{ \
\n ] \
\n ] \
\n ], \
\n "generation_timestamp": "2018-05-07 20:43:11", \
\n "generation_timestamp": "2018-05-07 20:43:57", \
\n "neurodocker_version": "0.3.2" \
\n}' > /neurodocker/neurodocker_specs.json
16 changes: 16 additions & 0 deletions casts/cast_ipython.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file contains ipython configuration variables to be used for generating
# asciinema demos to guarantee consistent appearance.

# make a fake temporary home dir and go into it
SCREENCAST_HOME=~/demo
if [ ! -e "$SCREENCAST_HOME" ]; then
mkdir -p ${SCREENCAST_HOME} || {
echo "FAILED to create $SCREENCAST_HOME" >&2
exit 1; # we need demo directory!
}
fi
cd $SCREENCAST_HOME
ipython

# cleanup at the end
trap "cd ; rm -rf ~/demo > /dev/null 2>&1" EXIT
112 changes: 112 additions & 0 deletions casts/cast_live_python
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/bin/bash
#
set -u -e

test ! -e $1 && echo "input file does not exist" && exit 1
title="$(echo $(basename $1) | sed -e 's/.sh$//')"
bashrc_file="$(dirname $0)/cast_ipython.rc"

# shortcut for making xdotool use the right window
function xdt() {
winid=$1
shift
xdotool windowactivate --sync $winid
if [ "$#" -gt 0 ]; then
xdotool "$@"
fi
}

# make sure the target xterm is up and running
width=106
height=29
fs=15
text_width=$(($width - 8))

geometry=${width}x${height}
this_window=$(xdotool getwindowfocus)

# For consistent appearance
xterm +sb -fa Hermit -fs $fs -bg black -fg white -geometry $geometry -title Screencast-xterm -e "bash --rcfile cast_ipython.rc" &
xterm_pid=$!
sleep 2

xterm_window=$(xdotool search --pid $xterm_pid)

# By default should stay in the xterm window, so when we need to deal with
# current one (waiting etc), then switch
function wait () {
xdt $this_window
read -p "$@" in
echo "$in"
xdt $xterm_window
}
function instruct () {
xdt $this_window
wait "$@"
}
function type () {
xdt $xterm_window type --clearmodifiers --delay 40 "$1"
}
function key () {
xdt $xterm_window key --clearmodifiers $*
}
function sleep () {
xdotool sleep $1
}
function execute () {
xdt $xterm_window sleep 0.5 key Return
sleep 0.2
}
function say()
{
ac=$(instruct "SAY: $1")
if [ "$ac" != "s" ] ; then
echo "skipping"
return
fi
type "$(printf "#\n# $1" | fmt -w ${text_width} --prefix '# ')"
key Return
}
function show () {
xdt $xterm_window type --clearmodifiers --delay 10 "$(printf "\n$1" | sed -e 's/^/# /g')"
sleep 0.1
key Return
}
function run () {
help="Press Enter to type, s to skip this action"
ac=$(instruct "EXEC: $1. $help")
if [ "$ac" = "s" ]; then
echo "skipping"
return
fi
type "$1"
ac=$(instruct "EXEC: $1. $help")
if [ "$ac" = "s" ]; then
echo "skipping"
return
fi
execute
}
function run_expfail () {
# TODO we could announce or visualize the expected failure
run "$1"
}

xdt $xterm_window sleep 0.1

echo "xterm PID $xterm_pid (window $xterm_window) this window $this_window"

# now get the process tree attached to the terminal so we can
# figure out when it is idle, and when it is not
# XXX must happen after asciinema is running
xterm_pstree="$(pstree -p -A $xterm_pid)"

. $1

sleep 1

show "$(cowsay "Demo was using $(datalad --version 2>&1 | head -n1). Discover more at http://datalad.org")"

# key Control_L+d

echo "INSTRUCTION: Press Ctrl-D or run exit to close the terminal"
100 changes: 100 additions & 0 deletions casts/nipype_tutorial_showcase.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
say "Import nipype building blocks"
show "Import nipype building blocks"
run "from nipype import Node, Workflow"

say "Import relevant interfaces"
show "Import relevant interfaces"
run "from nipype.interfaces.fsl import SliceTimer, MCFLIRT, Smooth"

say "Create SliceTime correction node"
show "Create SliceTime correction node"
run "slicetimer = Node(SliceTimer(index_dir=False,
interleaved=True,
time_repetition=2.5),
name='slicetimer')
"

say "Create Motion correction node"
show "Create Motion correction node"
run "mcflirt = Node(MCFLIRT(mean_vol=True,
save_plots=True),
name='mcflirt')
"

say "Create Smoothing node"
show "Create Smoothing node"
run "smooth = Node(Smooth(fwhm=4), name='smooth')"

say "Create Workflow"
show "Create Workflow"
run "preproc01 = Workflow(name='preproc01', base_dir='.')"

say "Connect nodes within the workflow"
show "Connect nodes within the workflow"
run "preproc01.connect([(slicetimer, mcflirt, [('slice_time_corrected_file', 'in_file')]),
(mcflirt, smooth, [('out_file', 'in_file')])])
"

say "Create a visualization of the workflow"
show "Create a visualization of the workflow"
run "preproc01.write_graph(graph2use='orig')"

say "Visualize the figure"
show "Visualize the figure"
run "!eog preproc01/graph_detailed.png
"

say "Feed some input to the workflow"
show "Feed some input to the workflow"
run "slicetimer.inputs.in_file = 'path/to/your/func.nii.gz'"

say "Run the Workflow and stop the time"
show "Run the Workflow and stop the time"
run "%time preproc01.run('MultiProc', plugin_args={'n_procs': 5})"

say "Investigate the output"
show "Investigate the output"
run "!tree preproc01 -I '*js|*json|*pklz|_report|*.dot|*html'"

say "Change the size of the smoothing kernel"
show "Change the size of the smoothing kernel"
run "smooth.inputs.fwhm = 2"

say "Rerun the workflow"
show "Rerun the workflow"
run "%time preproc01.run('MultiProc', plugin_args={'n_procs': 5})"

say "Create 4 additional copies of the workflow"
show "Create 4 additional copies of the workflow"
run "preproc02 = preproc01.clone('preproc02')
preproc03 = preproc01.clone('preproc03')
preproc04 = preproc01.clone('preproc04')
preproc05 = preproc01.clone('preproc05')
"

say "Create a new workflow - metaflow"
show "Create a new workflow - metaflow"
run "metaflow = Workflow(name='metaflow', base_dir='.')"

say "Add the 5 workflows to this metaflow"
show "Add the 5 workflows to this metaflow"
run "metaflow.add_nodes([preproc01, preproc02, preproc03,
preproc04, preproc05])
"

say "Visualize the workflow"
show "Visualize the workflow"
run "metaflow.write_graph(graph2use='flat')
!eog metaflow/graph_detailed.png
"

say "Run this metaflow in parallel"
show "Run this metaflow in parallel"
run "%time metaflow.run('MultiProc', plugin_args={'n_procs': 5})"

say "Investigate the output"
show "Investigate the output"
run "!tree metaflow -I '*js|*json|*pklz|_report|*.dot|*html'"

say "The End."
show "The End."
10 changes: 10 additions & 0 deletions index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@
" <a class=\"subject-link pure-u-1-4\" target=\"_blank\" href=\"https://github.com/kaczmarj/neurodocker\">Neurodocker</a>\n",
" <a class=\"subject-link pure-u-1-4\" target=\"_blank\" href=\"http://nipy.org/nibabel/\">NiBabel</a>\n",
" <a class=\"subject-link pure-u-1-4\" target=\"_blank\" href=\"http://nilearn.github.io/\">Nilearn</a>\n",
" <a class=\"subject-link pure-u-1-4\" target=\"_blank\" href=\"https://openneuro.org/\">OpenNeuro</a>\n",
" <a class=\"subject-link pure-u-1-4\" target=\"_blank\" href=\"http://bids-apps.neuroimaging.io\">BIDS Apps</a>\n",
" <a class=\"subject-link pure-u-1-4\" target=\"_blank\" href=\"http://fmriprep.readthedocs.io/en/latest/index.html\">fmriprep</a>\n",
" <a class=\"subject-link pure-u-1-4\" target=\"_blank\" href=\"https://mriqc.readthedocs.io/en/latest/#\">MRIQC</a>\n",
" <a class=\"subject-link pure-u-1-4\" target=\"_blank\" href=\"https://www.mindboggle.info/\">Mindboggle</a>\n",
" <a class=\"subject-link pure-u-1-4\" target=\"_blank\" href=\"https://timvanmourik.github.io/Porcupine/\">PORcupine</a>\n",
" </div>\n",
" <p>This section will give you helpful links and resources, so that you always know where to go to learn more.</p>\n",
"\n",
Expand Down Expand Up @@ -289,7 +294,12 @@
" <a class=\"subject-link pure-u-1-4\" target=\"_blank\" href=\"https://github.com/kaczmarj/neurodocker\">Neurodocker</a>\n",
" <a class=\"subject-link pure-u-1-4\" target=\"_blank\" href=\"http://nipy.org/nibabel/\">NiBabel</a>\n",
" <a class=\"subject-link pure-u-1-4\" target=\"_blank\" href=\"http://nilearn.github.io/\">Nilearn</a>\n",
" <a class=\"subject-link pure-u-1-4\" target=\"_blank\" href=\"https://openneuro.org/\">OpenNeuro</a>\n",
" <a class=\"subject-link pure-u-1-4\" target=\"_blank\" href=\"http://bids-apps.neuroimaging.io\">BIDS Apps</a>\n",
" <a class=\"subject-link pure-u-1-4\" target=\"_blank\" href=\"http://fmriprep.readthedocs.io/en/latest/index.html\">fmriprep</a>\n",
" <a class=\"subject-link pure-u-1-4\" target=\"_blank\" href=\"https://mriqc.readthedocs.io/en/latest/#\">MRIQC</a>\n",
" <a class=\"subject-link pure-u-1-4\" target=\"_blank\" href=\"https://www.mindboggle.info/\">Mindboggle</a>\n",
" <a class=\"subject-link pure-u-1-4\" target=\"_blank\" href=\"https://timvanmourik.github.io/Porcupine/\">PORcupine</a>\n",
" </div>\n",
" <p>This section will give you helpful links and resources, so that you always know where to go to learn more.</p>\n",
"\n",
Expand Down
54 changes: 48 additions & 6 deletions notebooks/advanced_create_interfaces.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,14 @@
"metadata": {},
"outputs": [],
"source": [
"TransformInfo().cmdline # This will CRASH"
"try:\n",
" TransformInfo().cmdline\n",
"\n",
"except(ValueError) as err:\n",
" print('It crashed with...')\n",
" print(\"ValueError:\", err)\n",
"else:\n",
" raise"
]
},
{
Expand All @@ -399,7 +406,14 @@
"metadata": {},
"outputs": [],
"source": [
"my_info_interface.inputs.in_file = 'idontexist.tfm' # This will CRASH, too"
"try:\n",
" my_info_interface.inputs.in_file = 'idontexist.tfm'\n",
"\n",
"except(Exception) as err:\n",
" print('It crashed with...')\n",
" print(\"TraitError:\", err)\n",
"else:\n",
" raise"
]
},
{
Expand Down Expand Up @@ -928,9 +942,23 @@
"source": [
"will_fail_at_run = TranslateImage(\n",
" in_file='/data/ds000114/sub-01/ses-test/anat/sub-01_ses-test_T1w.nii.gz',\n",
" out_file='translated.nii.gz')\n",
" out_file='translated.nii.gz')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"try:\n",
" result = will_fail_at_run.run()\n",
"\n",
"result = will_fail_at_run.run() # This will CRASH"
"except(NotImplementedError) as err:\n",
" print('It crashed with...')\n",
" print(\"NotImplementedError:\", err)\n",
"else:\n",
" raise"
]
},
{
Expand Down Expand Up @@ -978,9 +1006,23 @@
"source": [
"half_works = TranslateImage(\n",
" in_file='/data/ds000114/sub-01/ses-test/anat/sub-01_ses-test_T1w.nii.gz',\n",
" out_file='translated_nipype.nii.gz')\n",
" out_file='translated_nipype.nii.gz')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"try:\n",
" result = half_works.run()\n",
"\n",
"result = half_works.run() # This will CRASH, too"
"except(NotImplementedError) as err:\n",
" print('It crashed with...')\n",
" print(\"NotImplementedError:\", err)\n",
"else:\n",
" raise"
]
},
{
Expand Down
8 changes: 4 additions & 4 deletions test_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def _notebook_run(path):
ep.preprocess(nb, {'metadata': {'path': this_file_directory}})

except CellExecutionError as e:
if "TAB" in e.traceback or "CRASH" in e.traceback:
if "TAB" in e.traceback:
print(str(e.traceback).split("\n")[-2])
else:
raise e
Expand Down Expand Up @@ -85,9 +85,9 @@ def reduce_notebook_load(path):
Dir_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "notebooks")

@pytest.mark.parametrize("notebook",
glob(os.path.join(Dir_path, "introduction_*.ipynb")) +
glob(os.path.join(Dir_path, "basic*.ipynb")) +
glob(os.path.join(Dir_path, "advanced*.ipynb")) +
sorted(glob(os.path.join(Dir_path, "introduction_*.ipynb"))) +
sorted(glob(os.path.join(Dir_path, "basic*.ipynb"))) +
sorted(glob(os.path.join(Dir_path, "advanced*.ipynb"))) +
[os.path.join(Dir_path, "example_preprocessing.ipynb"),
os.path.join(Dir_path, "example_1stlevel.ipynb"),
os.path.join(Dir_path, "example_normalize.ipynb"),
Expand Down

0 comments on commit 2cf5af2

Please sign in to comment.