コード例 #1
0
ファイル: bids.py プロジェクト: gpiantoni/grvx
def get_bids(bids_dir, subject):
    from bidso.find import find_in_bids

    return (
        'sub-' + subject,
        str(
            find_in_bids(bids_dir,
                         subject=subject,
                         modality='T1w',
                         extension='.nii.gz')),
        str(
            find_in_bids(bids_dir,
                         subject=subject,
                         modality='bold',
                         extension='.nii.gz')),
        str(
            find_in_bids(bids_dir,
                         subject=subject,
                         modality='ieeg',
                         extension='.eeg')),
        str(
            find_in_bids(bids_dir,
                         subject=subject,
                         modality='electrodes',
                         extension='.tsv')),
    )
コード例 #2
0
ファイル: test_03_find.py プロジェクト: gpiantoni/bidso
def test_find_in_bids_01():

    found = find_in_bids(filename, subject='bert', session='day01', run='1',
                         extension='.nii.gz', upwards=True)
    assert found.name == 'sub-bert_ses-day01_task-motor_run-1_bold.nii.gz'

    with warns(UserWarning):
        find_in_bids(filename, subject='bert', useless='xxx', task='motor',
                     modality='channels', upwards=True)
コード例 #3
0
ファイル: feat_on_surf.py プロジェクト: gpiantoni/boavus
def xmain(analysis_dir,
          freesurfer_dir,
          output_dir,
          modality='compare',
          surface='white',
          surf_fwhm=0):
    """
    map feat values on freesurfer surface',

    Parameters
    ----------
    analysis_dir : path

    freesurfer_dir : path

    output_dir : path

    modality : str
        "compare"
    surface : str
        "white", "pial"
    surf_fwhm : float
        FWHM
    """
    p_all = []
    surfs = []
    for in_vol_file in find_in_bids(analysis_dir,
                                    generator=True,
                                    extension='.nii.gz',
                                    modality=modality):
        in_vol = file_Core(in_vol_file)
        feat_path = find_in_bids(analysis_dir,
                                 subject=in_vol.subject,
                                 extension='.feat')
        for hemi in ('lh', 'rh'):
            p, out_surf = vol2surf(in_vol, feat_path, freesurfer_dir, hemi,
                                   surface, surf_fwhm)
            p_all.append(p)
            surfs.append(out_surf)

    # wait for all processes to run
    [p.wait() for p in p_all]
    [check_subprocess(p) for p in p_all]
    [info['mri_nonan'].unlink() for info in surfs]

    img_dir = output_dir / SURF_DIR
    rmtree(img_dir, ignore_errors=True)
    img_dir.mkdir(exist_ok=True, parents=True)

    for one_surf in surfs:
        plot_surf(img_dir, freesurfer_dir, one_surf, surface)
コード例 #4
0
ファイル: broadband.py プロジェクト: gpiantoni/grvx
def main(analysis_dir, bands=[], method="5", noparallel=False):
    """
    extract timefrequency after bandpass

    Parameters
    ----------
    analysis_dir : path

    bands : str
        write down frequency bands as 70-90,90-110 (no spaces)
    method : str
        "1", "2", "3", "4", "5"
    noparallel : bool
        if it should run serially (i.e. not parallely, mostly for debugging)
    """
    # convert str "70-90,90-110" to [[70, 90], [90, 110]]
    bands = [[float(f) for f in b.split('-')] for b in bands.split(',')]

    args = []
    for ieeg_file in find_in_bids(analysis_dir,
                                  modality='ieegproc',
                                  extension='.pkl',
                                  generator=True):
        args.append((ieeg_file, bands, method))

    if noparallel:
        for arg in args:
            save_frequency(*arg)
    else:
        with Pool() as p:
            p.starmap(save_frequency, args)
コード例 #5
0
ファイル: assign_regions.py プロジェクト: gpiantoni/boavus
def xmain(bids_dir, freesurfer_dir, acquisition='clinical', noparallel=False):
    """
    assign electrodes to brain regions',

    Parameters
    ----------
    bids_dir : path

    freesurfer_dir : path

    acquisition : str
        acquisition type of the electrode files
    noparallel : bool
        if it should run serially (i.e. not parallely, mostly for debugging)
    """
    args = []
    for electrode_path in find_in_bids(bids_dir,
                                       generator=True,
                                       acquisition=acquisition,
                                       modality='electrodes',
                                       extension='.tsv'):
        elec = Electrodes(electrode_path)
        fs = Freesurfer(freesurfer_dir / ('sub-' + elec.subject))
        args.append((elec, fs))

    if noparallel:
        for arg in args:
            assign_regions(*arg)
    else:
        with Pool(processes=4) as p:
            p.starmap(assign_regions, args)
コード例 #6
0
ファイル: coreg.py プロジェクト: gpiantoni/boavus
def xmain(analysis_dir, freesurfer_dir):
    """
    coreg feat with freesurfer

    Parameters
    ----------
    analysis_dir : path

    freesurfer_dir : path

    """

    for feat_path in find_in_bids(analysis_dir, generator=True, extension='.feat'):
        lg.debug(f'Reading {feat_path}')
        coreg_feat2freesurfer(feat_path, freesurfer_dir)
コード例 #7
0
ファイル: fit.py プロジェクト: gpiantoni/boavus
def xmain(analysis_dir,
          method="analyzePRF",
          task='bairprf',
          input='ieegprocpsd',
          noparallel=False):
    """
    compute psd for two conditions

    Parameters
    ----------
    analysis_dir : path

    method : str
        "popeye" or "analyzePRF"
    task : str
        task to analyze
    input : str
        name of the modality of the preceding step
    noparallel : bool
        if it should run serially (i.e. not parallely, mostly for debugging)
    """
    args = []
    for prf_file in find_in_bids(analysis_dir,
                                 task=task,
                                 modality=input,
                                 extension='.pkl',
                                 generator=True):
        if input.startswith('ieeg'):
            funct = estimate_ieeg_prf

        elif input.startswith('bold'):
            funct = estimate_bold_prf

        else:
            raise ValueError(f'Unknown modality {input}')

        args.append((funct, prf_file, method))

    if noparallel:
        for arg in args:
            args[0](*arg[1:])
    else:
        with Pool() as p:
            p.starmap(arg[0], arg[1:])
コード例 #8
0
ファイル: plot.py プロジェクト: gpiantoni/boavus
def xmain(bids_dir,
          analysis_dir,
          freesurfer_dir,
          output_dir,
          acquisition='clinical',
          measure_modality="",
          measure_column=""):
    """
    plot electrodes onto the brain surface,

    Parameters
    ----------
    bids_dir : path

    analysis_dir : path

    freesurfer_dir : path

    output_dir : path

    acquisition : str
        acquisition type of the electrode files
    measure_modality : str
        modality
    measure_column : str
        column
    """
    img_dir = output_dir / ELECSURF_DIR
    rmtree(img_dir, ignore_errors=True)
    img_dir.mkdir(exist_ok=True, parents=True)

    for electrode_path in find_in_bids(bids_dir,
                                       generator=True,
                                       acquisition=acquisition,
                                       modality='electrodes',
                                       extension='.tsv'):
        lg.debug(f'Reading electrodes from {electrode_path}')
        elec = Electrodes(electrode_path)
        fs = Freesurfer(freesurfer_dir / ('sub-' + elec.subject))

        labels = None
        if measure_modality != "":
            try:
                ecog_file = find_in_bids(analysis_dir,
                                         subject=elec.subject,
                                         modality=measure_modality,
                                         extension='.tsv')
            except FileNotFoundError as err:
                lg.warning(err)
                continue

            lg.debug(f'Reading {measure_column} from {ecog_file}')
            ecog_tsv = read_tsv(ecog_file)

            labels = [x['name'] for x in elec.electrodes.tsv]
            labels, vals = read_channels(ecog_tsv, labels, measure_column)

        else:
            vals = None

        v = plot_electrodes(elec, fs, labels, vals)

        png_file = img_dir / replace_underscore(elec.get_filename(),
                                                'surfaceplot.png')
        lg.debug(f'Saving electrode plot on {png_file}')
        v.save(png_file)
        v.close()
コード例 #9
0
ファイル: test_03_find.py プロジェクト: gpiantoni/bidso
def test_find_in_bids_06():
    with raises(ValueError):
        find_in_bids(BIDS_PATH, upwards=True, generator=True)
コード例 #10
0
ファイル: test_03_find.py プロジェクト: gpiantoni/bidso
def test_find_in_bids_05():
    with raises(FileNotFoundError):
        find_in_bids(BIDS_PATH, subject='xxx')

    with raises(StopIteration):
        next(find_in_bids(BIDS_PATH, subject='xxx', generator=True))
コード例 #11
0
ファイル: test_03_find.py プロジェクト: gpiantoni/bidso
def test_find_in_bids_04():
    assert sum(1 for x in find_in_bids(BIDS_PATH, generator=True, subject='bert')) == 21
コード例 #12
0
ファイル: test_03_find.py プロジェクト: gpiantoni/bidso
def test_find_in_bids_03():

    with raises(FileNotFoundError):
        find_in_bids(filename, upwards=True, subject='bert')