Пример #1
0
 def bxplot(stats, label):
     stats = concat_ts_boxplot_stats(stats)
     # XXX need some way to expose whether there were missing subjects and
     # report proper IDs -- for now resort to whining
     verbose(
         0,
         "List of outlier time series follows (if any) [note, subject IDs are enumarations and may differ from dataset subject IDs in case of missing subjects]"
     )
     for i, run in enumerate([
             np.where(np.sum(np.logical_not(o.mask), axis=0))
             for o in stats[1]
     ]):
         sids = run[0]
         if len(sids):
             verbose(0,
                     "%s r%.3i: %s" % (label, i + 1, [s + 1 for s in sids]))
     timeseries_boxplot(stats[0]['median'],
                        mean=stats[0]['mean'],
                        std=stats[0]['std'],
                        n=stats[0]['n'],
                        min=stats[0]['min'],
                        max=stats[0]['max'],
                        p25=stats[0]['p25'],
                        p75=stats[0]['p75'],
                        outlierd=stats[1],
                        segment_sizes=segment_sizes)
     pl.title(label)
     xp, xl = pl.xticks()
     pl.xticks(xp, ['' for i in xl])
     pl.xlim((0, len(stats[0]['n'])))
     pl.ylabel(plt_props[label])
Пример #2
0
def motionqc_plot(data, outlier_abs_minthresh=None, outlier_stdthresh=None, ylabel=None):
    import pylab as pl
    from mvpa2.misc.plot import timeseries_boxplot, concat_ts_boxplot_stats
    from mvpa2.misc.stats import compute_ts_boxplot_stats

    # segments x [subjects x timepoints x props]
    segment_sizes = [d.shape[1] for d in data]

    # get stats for all segments and concatenate them
    stats = concat_ts_boxplot_stats(
        [compute_ts_boxplot_stats(
            d,
            outlier_abs_minthresh=outlier_abs_minthresh,
            outlier_thresh=outlier_stdthresh,
            aggfx=np.linalg.norm,
            greedy_outlier=True)
            for d in data])

    outlier = None
    if outlier_stdthresh:
        outlier = [list(np.where(np.sum(np.logical_not(o.mask), axis=0))[0])
                   for o in stats[1]]

    # plot
    timeseries_boxplot(
        stats[0]['median'],
        mean=stats[0]['mean'],
        std=stats[0]['std'],
        n=stats[0]['n'],
        min=stats[0]['min'],
        max=stats[0]['max'],
        p25=stats[0]['p25'],
        p75=stats[0]['p75'],
        outlierd=stats[1],
        segment_sizes=segment_sizes)
    xp, xl = pl.xticks()
    pl.xticks(xp, ['' for i in xl])
    pl.xlim((0, len(stats[0]['n'])))
    if ylabel:
        pl.ylabel(ylabel)

    pl.xlabel('time')

    return outlier
Пример #3
0
 def bxplot(stats, label):
     stats = concat_ts_boxplot_stats(stats)
     verbose(0, "List of outlier time series follows (if any)")
     for i, run in enumerate([np.where(np.sum(np.logical_not(o.mask), axis=0))
                           for o in stats[1]]):
         sids = run[0]
         if len(sids):
             verbose(0, "%s r%.3i: %s"
                        % (label, i + 1, [s + 1 for s in sids]))
     timeseries_boxplot(stats[0]['median'],
             mean=stats[0]['mean'], std=stats[0]['std'], n=stats[0]['n'],
             min=stats[0]['min'], max=stats[0]['max'],
             p25=stats[0]['p25'], p75=stats[0]['p75'],
             outlierd=stats[1], segment_sizes=segment_sizes)
     pl.title(label)
     xp, xl = pl.xticks()
     pl.xticks(xp, ['' for i in xl])
     pl.xlim((0, len(stats[0]['n'])))
     pl.ylabel(plt_props[label])
Пример #4
0
 def bxplot(stats, label):
     stats = concat_ts_boxplot_stats(stats)
     # XXX need some way to expose whether there were missing subjects and
     # report proper IDs -- for now resort to whining
     verbose(0, "List of outlier time series follows (if any) [note, subject IDs are enumarations and may differ from dataset subject IDs in case of missing subjects]")
     for i, run in enumerate([np.where(np.sum(np.logical_not(o.mask), axis=0))
                           for o in stats[1]]):
         sids = run[0]
         if len(sids):
             verbose(0, "%s r%.3i: %s"
                        % (label, i + 1, [s + 1 for s in sids]))
     timeseries_boxplot(stats[0]['median'],
             mean=stats[0]['mean'], std=stats[0]['std'], n=stats[0]['n'],
             min=stats[0]['min'], max=stats[0]['max'],
             p25=stats[0]['p25'], p75=stats[0]['p75'],
             outlierd=stats[1], segment_sizes=segment_sizes)
     pl.title(label)
     xp, xl = pl.xticks()
     pl.xticks(xp, ['' for i in xl])
     pl.xlim((0, len(stats[0]['n'])))
     pl.ylabel(plt_props[label])
Пример #5
0
def run(args):
    import numpy as np
    import pylab as pl
    from mvpa2.datasets.sources.openfmri import OpenFMRIDataset
    from mvpa2.misc.plot import timeseries_boxplot, concat_ts_boxplot_stats
    from mvpa2.misc.stats import compute_ts_boxplot_stats

    of = OpenFMRIDataset(args.path)
    data = of.get_task_bold_attributes(
            args.task, args.estimate_fname, np.loadtxt,
            exclude_subjs=args.exclude_subjs)
    segment_sizes = [len(d[0]) for d in data]

    # figure setup
    pl.figure(figsize=(12, 5))
    ax = pl.subplot(211)

    # translation
    run_stats = [compute_ts_boxplot_stats(
                    d[...,:3],
                    outlier_abs_minthresh=args.outlier_minthresh,
                    outlier_thresh=args.outlier_stdthresh,
                    aggfx=np.linalg.norm,
                    greedy_outlier=True)
                        for d in data]
    stats = concat_ts_boxplot_stats(run_stats)

    timeseries_boxplot(stats[0]['median'],
                mean=stats[0]['mean'], std=stats[0]['std'], n=stats[0]['n'],
                min=stats[0]['min'], max=stats[0]['max'],
                p25=stats[0]['p25'], p75=stats[0]['p75'],
                outlierd=stats[1], segment_sizes=segment_sizes)
    pl.title('translation')
    xp, xl = pl.xticks()
    pl.xticks(xp, ['' for i in xl])
    pl.xlim((0, len(stats[0]['n'])))
    #pl.ylim((0,7))
    pl.ylabel('estimate L2-norm in mm')

    # rotation
    ax = pl.subplot(212)
    run_stats = [compute_ts_boxplot_stats(
                    d[...,3:],
                    outlier_abs_minthresh=args.outlier_minthresh,
                    outlier_thresh=args.outlier_stdthresh,
                    aggfx=np.linalg.norm,
                    greedy_outlier=True)
                        for d in data]
    stats = concat_ts_boxplot_stats(run_stats)

    timeseries_boxplot(stats[0]['median'],
                mean=stats[0]['mean'], std=stats[0]['std'], n=stats[0]['n'],
                min=stats[0]['min'], max=stats[0]['max'],
                p25=stats[0]['p25'], p75=stats[0]['p75'],
                outlierd=stats[1], segment_sizes=segment_sizes)

    pl.xlim((0, len(stats[0]['n'])))
    #pl.ylim((0,5))
    pl.title('rotation')
    pl.ylabel('estimate L2-norm in deg')
    pl.xlabel('time in fMRI volumes')

    if args.savefig is None:
        pl.show()
    else:
        pl.savefig(args.safefig)