-
Notifications
You must be signed in to change notification settings - Fork 65
added spm12 standalone installer; and script to extract timings from dicom files #231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 <<EOF > $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} | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The get_slice_indices function has been fixed for the bug you spotted, so I'd advice using it. It's useful if slice_order == "interleaved", in fact it does general sanitization. See comments on line 197 below. |
||
|
|
||
| # 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| ignore_exception=False | ||
| ) | ||
| if stc_result.outputs is None: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 """ | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I remember good, we were considering hosting a small dataset (say on NTRC), that could be used here to make this demo self-contained. Any update ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, I have put a dataset at: https://www.nitrc.org/frs/download.php/9035/epi-example-dicom.tar.gz As soon as spm12 works in the master branch of pypreprocess, I will test it I still need to write code to fetch the dataset... Chris Christophe Pallier Contact info: http://www.pallier.org/w/pmwiki.php/Main/Contact On Sun, Jun 19, 2016 at 1:18 PM, DOHMATOB Elvis [email protected]
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On Sun, Jun 19, 2016 at 2:47 PM, Christophe Pallier <
Elvis Dohmatob,
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have just tried with a list of integers (slice numbers) for slice_order: slice_order = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 and got a crash: File "/home/cp983411/code/pypreprocess/pypreprocess/slice_timing.py", line 56, in get_slice_indices It seems that the list is recognized a a string (isinstance(slice_order, basestring) is True), should I use a list syntax with '[' '],' and ','?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, it works with the python list syntax
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well, it crashes further down the line: 160620-09:42:23,548 workflow INFO: But this maybe because it is an unsual use case (?). For the *.ini: #% output_dir = essai
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On Mon, Jun 20, 2016 at 9:34 AM, Christophe Pallier <
Elvis Dohmatob,
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On Mon, Jun 20, 2016 at 9:46 AM, Christophe Pallier <
Elvis Dohmatob, |
||
| 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.)) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, this would go in a separate PR as it has nothing to do with spm12 standalon installation or STC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to learn how to do better PR ;-)
I only have one branch on my fork of pypreprocess. Should I have created
different branches for different dev?
Chris
Christophe Pallier
Contact info: http://www.pallier.org/w/pmwiki.php/Main/Contact
On Sun, Jun 19, 2016 at 1:15 PM, DOHMATOB Elvis [email protected]
wrote:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Sun, Jun 19, 2016 at 2:50 PM, Christophe Pallier <
[email protected]> wrote:
Elvis Dohmatob,
sent from my potato...
http://dohmatob.blogspot.fr/, https://team.inria.fr/parietal/elvis/,
https://github.com/dohmatob