Example #1
0
def _demo_runner(subjects, dataset_id, **spm_realign_kwargs):
    """Demo runner.

    Parameters
    ----------
    subjects: iterable for subject data
        each subject data can be anything, with a func (string or list
        of strings; existing file path(s)) and an output_dir (string,
        existing dir path) field
    dataset_id: string
        a short string describing the data being processed (e.g. "HAXBY!")

    Notes
    -----
    Don't invoke this directly!

    """

    # loop over subjects
    for subject_data in subjects:
        print("%sMotion correction for %s (%s)" % ('\t' * 2,
                                                   subject_data.subject_id,
                                                   dataset_id))

        # instantiate realigner
        mrimc = MRIMotionCorrection(**spm_realign_kwargs)

        # fit realigner
        mrimc.fit(subject_data.func)

        # write realigned files to disk
        mrimc.transform(subject_data.output_dir, reslice=True, concat=True)

        # plot results
        for sess, rp_filename in zip(xrange(len(mrimc._rp_filenames_)),
                                     mrimc._rp_filenames_):
            plot_spm_motion_parameters(
                rp_filename,
                title="Estimated motion for %s (session %i) of '%s'" % (
                    subject_data.subject_id, sess, dataset_id))

        plt.show()
def _demo_runner(subjects, dataset_id, **spm_realign_kwargs):
    """Demo runner.

    Parameters
    ----------
    subjects: iterable for subject data
        each subject data can be anything, with a func (string or list
        of strings; existing file path(s)) and an output_dir (string,
        existing dir path) field
    dataset_id: string
        a short string describing the data being processed (e.g. "HAXBY!")

    Notes
    -----
    Don't invoke this directly!

    """

    # loop over subjects
    for subject_data in subjects:
        print("%sMotion correction for %s (%s)" % ('\t' * 2,
                                                   subject_data.subject_id,
                                                   dataset_id))

        # instantiate realigner
        mrimc = MRIMotionCorrection(**spm_realign_kwargs)

        # fit realigner
        mrimc = mem.cache(mrimc.fit)(subject_data.func)

        # write realigned files to disk
        mem.cache(mrimc.transform)(subject_data.output_dir, reslice=False,
                                   concat=False)

        # plot results
        for sess, rp_filename in zip(
                xrange(len(mrimc.realignment_parameters_)),
                mrimc.realignment_parameters_):
            plot_spm_motion_parameters(
                rp_filename,
                title="Estimated motion for %s (session %i) of '%s'" % (
                    subject_data.subject_id, sess, dataset_id))
Example #3
0
                                      prepreproc_undergone="",
                                      caching=True)

    return subject_data


##### Start preprocessing for one subject

subject_data = do_preproc(funcfile, anatfile, args.subject, decimate=False)
subject_data.func

# #### Perform some quality checks for one subject
#
# First we can check the motion parameters:
plot_spm_motion_parameters(
    subject_data.nipype_results["realign"].outputs.realignment_parameters,
    title="Realign: estimated motion.")
plt.savefig(os.path.join(outdir, filename_prefix + '_motion_params.png'))
plt.close()

# We can also check the coregistration:
plot_registration(
    anatfile,
    subject_data.nipype_results["coreg"].outputs.coregistered_files,
    close=False,
    cut_coords=(-10, 20, 5),
    title="Coregister outline.")
plt.savefig(os.path.join(outdir, filename_prefix + '_coregistration.png'))
plt.close()

# And the normalization:
Example #4
0
"""
    Plotting PSYDAT alignment results
"""

import os, glob
from pypreprocess.reporting.check_preprocessing import plot_spm_motion_parameters

BASE_DIR = os.path.join('/', 'shfj', 'Ppsypim', 'PSYDAT', 'Subjects')
FIG_BASE_DIR = os.path.join('figures')

subject_path_list = glob.glob(os.path.join(BASE_DIR, 'S*'))

for sp in subject_path_list:
    root, subject_id = os.path.split(sp)

    mid_dir = os.path.join(sp, 'MRI', 'MID')
    if os.path.isdir(mid_dir):
        # Plot Realign
        mvt = glob.glob(os.path.join(mid_dir, '*.txt'))
        if len(mvt)>0:
            realign_fig = os.path.join(FIG_BASE_DIR, 'realign', subject_id)
            plot_spm_motion_parameters(mvt[0],
                                       title=subject_id,
                                       output_filename=realign_fig)