diff --git a/README.rst b/README.rst old mode 100755 new mode 100644 index fb1f8cac..76de3e19 --- a/README.rst +++ b/README.rst @@ -186,3 +186,5 @@ Common problems and fixes ========================= * libXp.so.6 missing (in ubuntu >= 15.10, for example) This is a known is http://askubuntu.com/questions/719839/libxp-so-6-missing-15-10. The idea is to install it manually from official sources https://launchpad.net/ubuntu/wily/+package/libxp6 + +* Beware: the pathname for "scratch" (directory for cache) must not contain any space character! This triggered a nasty bug in nipype.... diff --git a/continuous_integration/install_spm12.sh b/continuous_integration/install_spm12.sh new file mode 100644 index 00000000..e9dc5436 --- /dev/null +++ b/continuous_integration/install_spm12.sh @@ -0,0 +1,47 @@ +#! /bin/bash +set -e + +# set -x # echo on + +SPM_ROOT_DIR=~/opt/spm12 # Installation directory + +SPM_SRC=spm12_r6685.zip +MCRINST=MCRInstaller.bin + +mkdir -p $SPM_ROOT_DIR && cd $SPM_ROOT_DIR + +if [ ! -d spm12 ]; then + if [ ! -f ${SPM_SRC} ]; then + wget http://www.fil.ion.ucl.ac.uk/spm/download/restricted/utopia/${SPM_SRC} + fi + unzip -q ${SPM_SRC} + chmod 755 spm12/run_spm12.sh +fi + +if [ ! -d mcr ]; then + if [ ! -f MCRInstaller.bin ]; then + wget http://www.fil.ion.ucl.ac.uk/spm/download/restricted/utopia/MCR/glnxa64/${MCRINST} + fi + chmod 755 ${MCRINST} + ./${MCRINST} -P bean421.installLocation="mcr" -silent +fi + + +if [ ! -f $SPM_ROOT_DIR/spm12.sh ]; then + cat < $SPM_ROOT_DIR/spm12.sh +#!/bin/bash +SPM12_STANDALONE_HOME=$SPM_ROOT_DIR/spm12 +exec "\${SPM12_STANDALONE_HOME}/run_spm12.sh" "\${SPM12_STANDALONE_HOME}/../mcr/v713" \${1+"\$@"} +EOF + + chmod 755 $SPM_ROOT_DIR/spm12.sh +fi + +# Create CTF +$SPM_ROOT_DIR/spm12.sh quit +cmds="export SPM_DIR=$SPM_ROOT_DIR/spm12/; export SPM_MCR=$SPM_ROOT_DIR/spm12.sh" +${cmds} +echo "You may want to add the following commands (the exports) to your ~/.bashrc file once and for all." +echo +echo ${cmds} + diff --git a/pypreprocess/nipype_preproc_spm_utils.py b/pypreprocess/nipype_preproc_spm_utils.py index a5f6df86..0b343d16 100644 --- a/pypreprocess/nipype_preproc_spm_utils.py +++ b/pypreprocess/nipype_preproc_spm_utils.py @@ -143,20 +143,19 @@ def _do_subject_slice_timing(subject_data, TR, TA=None, spm_dir=None, # compute nslices nslices = load_vols(subject_data.func[0])[0].shape[2] - assert 1 <= ref_slice <= nslices, ref_slice +# assert 1 <= ref_slice <= nslices, ref_slice - # compute slice indices / order - if not isinstance(slice_order, basestring): - slice_order = np.array(slice_order) - 1 - slice_order = get_slice_indices(nslices, slice_order=slice_order, - interleaved=interleaved) +# # compute slice indices / order +# if not isinstance(slice_order, basestring): +# slice_order = np.array(slice_order) - 1 +# slice_order = get_slice_indices(nslices, slice_order=slice_order, +# inter leaved=interleaved) # use pure python (pp) code ? if software == "python": return _pp_do_subject_slice_timing(subject_data, ref_slice=ref_slice, slice_order=slice_order, - caching=caching) - + caching=caching) # sanitize software choice if software != "spm": raise NotImplementedError( @@ -193,8 +192,9 @@ def _do_subject_slice_timing(subject_data, TR, TA=None, spm_dir=None, for sess_func in subject_data.func: stc_result = stc(in_files=sess_func, time_repetition=TR, time_acquisition=TA, num_slices=nslices, - ref_slice=ref_slice + 1, - slice_order=list(slice_order + 1), # SPM + ref_slice=ref_slice, + #slice_order=list(slice_order + 1), # SPM8 ? + slice_order=[int(x) for x in slice_order.split()], # SPM12 ignore_exception=False ) if stc_result.outputs is None: diff --git a/scripts/extract_timings.py b/scripts/extract_timings.py new file mode 100644 index 00000000..f2baab77 --- /dev/null +++ b/scripts/extract_timings.py @@ -0,0 +1,39 @@ +#! /usr/bin/env python +# Time-stamp: <2016-05-31 14:58:27 chrplr> +# + +""" Extracts slice timing information from a dicom file. +To be passed as argument to slice_order for slice timing correction algorithms """ + +from __future__ import print_function +import os +import glob +import dicom +import sys + +try: + dicom_path = sys.argv[1] + + if os.path.isdir(dicom_path): + dicom_ref = sorted(glob.glob(os.path.join(dicom_path, '*.dcm')))[4] + else: + if (os.path.isfile(dicom_path)): + dicom_ref = dicom_path + + TR = dicom.read_file(dicom_ref).RepetitionTime + slice_times = dicom.read_file(dicom_ref)[0x19, 0x1029].value + nb_slices = len(slice_times) + +except: + print("Unexpected error: %s" % sys.exc_info()[0]) + print("\nUsage:\n %s dicom_path\nWhere dicom_path is a dicom directory" % sys.argv[0]) + sys.exit(-1) + +print("TR = %.3f" % (TR/1000.)) +#print("nb_slices = %d" % nb_slices) +print("slice_timings = ", end=" ") +for v in slice_times: + print("%.1f" % v, end=" ") +print("\n", end="") +print("refslice = %.3f" % (TR/2000.)) +