Beispiel #1
0
    def save_all_pages(self, fname=None):
        if fname is None:
            msg = ("Save all pages. Index is inserted before extension. "
                   "If no extension is provided, pdf is used.")
            fname = ui.ask_saveas("title", msg, None)
            if not fname:
                return

        head, tail = os.path.split(fname)
        if os.path.extsep in tail:
            root, ext = os.path.splitext(tail)
        else:
            root = fname
            ext = '.pdf'
        fntemp = os.path.join(head, root) + '_%i' + ext

        i = self.current_page_i
        self.figure.savefig(fntemp % i)
        pages = range(self.n)
        pages.remove(i)
        prog = ui.progress_monitor(self.n - 1, "Saving Figures", "Saving Figures")
        for i in pages:
            self.show_page(i)
            self.figure.savefig(fntemp % i)
            prog.advance()
        prog.terminate()
Beispiel #2
0
def mri_annotation2label(subject='*', annot='aparc',
                         dest=os.path.join("{sdir}", "label", "{annot}"),
                         hemi='*', subjects_dir=None):
    """
    Calls ``mri_annotation2label`` (`freesurfer wiki
    <http://surfer.nmr.mgh.harvard.edu/fswiki/mri_annotation2label>`_)

    mri_dir : str(path)
        Path containing mri subject directories (freesurfer's ``SUBJECTS_DIR``).

    subject : str
        Name of the subject ('*' uses fnmatch to find folders in ``mri_dir``).

    annot : str
        Name of the annotation file (e.g., ``'aparc'``, ...).

    dest : str(path)
        Destination for the label files. {sdir}" and "{annot}" are filled in
        appropriately.

    hemi : 'lh' | 'rh' | '*'
        Hemisphere to process; '*' proceses both.

    """
    hemis = _fs_hemis(hemi)
    subjects = _fs_subjects(subject)
    subjects_dir = get_subjects_dir(subjects_dir)

    # progress monitor
    i_max = len(subjects) * len(hemis)
    if len(subjects) > 1:
        prog = ui.progress_monitor(i_max, "mri_annotation2label", "")
    else:
        prog = None

    for subject in subjects:
        sdir = os.path.join(subjects_dir, subject)
        outdir = dest.format(sdir=sdir, annot=annot)

        for hemi in hemis:
            if prog:
                prog.message("Processing: %s - %s" % (subject, hemi))

            cmd = [get_bin("freesurfer", "mri_annotation2label"),
                   '--annotation', annot,
                   '--subject', subject,
                   '--hemi', hemi,
                   '--outdir', outdir,
                   ]

            _run(cmd, cwd=subjects_dir)
            if prog:
                prog.advance()
Beispiel #3
0
from eelbrain import ui
import time

p = ui.progress_monitor(i_max=10, title='Progress', message='msg 1!', cancel=True)
for i in xrange(10):
    p.message("sleeping for %s" % i)
    time.sleep(.3)
    p.advance("%s done!" % i)
    time.sleep(.2)
    """

    To remove the progress_monitor prematurely, uncomment the following three 
    lines:
    """
##    if i == 7:
##        p.terminate()
##        break

    """

    To cause a crash while the progress_monitor is shown, uncomment the 
    following two lines. To clear up the progress_monitor after the crash,
    call::

        >>> ui.kill_progress_monitors()

    """
##    if i == 6:
##        print 6/0