Skip to content

Instantly share code, notes, and snippets.

import numpy as np
import pandas as pd
import nibabel as nib
from pathlib import Path, PurePath
from nilearn import image
from numpy.lib import recfunctions
from nilearn.input_data import NiftiMasker
from nistats.first_level_model import FirstLevelModel
"""
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@emdupre
emdupre / access_OSF_API.py
Created April 1, 2019 16:59
Pull download keys for all files listed in an OSF repository
import json
import re
import requests
repo = '5hju4' # my example repository, update as appropriate
query = '?filter[name][contains]=confounds_regressors.tsv' # my example query, update or leave blank as appropriate
url = 'https://api.osf.io/v2/nodes/{0}/files/osfstorage/{1}'.format(repo, query)
guids = []
while True:
@emdupre
emdupre / tedana_outputs_w_3.2.rst
Created January 11, 2019 14:33
Tedana outputs with version 3.2 of the selection criteria, created by @tsalo

Outputs of tedana

tedana derivatives

t2sv.nii Limited estimated T2* 3D map.

@emdupre
emdupre / hypercommented_v3_selcomps.py
Created November 26, 2018 15:50
Hypercommenting of the v3.2 tedana selection criteria
"""
Functions to identify TE-dependent and TE-independent components.
"""
import json
import logging
import pickle
from nilearn._utils import check_niimg
import numpy as np
from scipy import stats
@emdupre
emdupre / group_echos.py
Created January 8, 2018 17:06
A function to group multi-echo fMRI BOLD sessions, for use in FMRIPREP.
import re
from itertools import groupby
multi_echo_ses = {'data': ['sub-01_ses-01_task-view_run-01_echo-1_bold.nii.gz',
'sub-01_ses-01_task-view_run-01_echo-2_bold.nii.gz',
'sub-01_ses-01_task-view_run-01_echo-3_bold.nii.gz',
'sub-01_ses-01_task-view_run-02_echo-1_bold.nii.gz',
'sub-01_ses-01_task-view_run-02_echo-2_bold.nii.gz',
'sub-01_ses-01_task-view_run-02_echo-3_bold.nii.gz',
'sub-01_ses-01_task-rest_run-01_bold.nii.gz',
@emdupre
emdupre / maskadmask.py
Last active November 30, 2017 20:02
Cleaned up makeadmask
def create_last_echo_mask(echo_list):
"""
Make a map of longest echo that a voxel can be sampled with,
with minimum value of map as X value of voxel that has median
value in the 1st echo. N.B. larger factor leads to bias to lower TEs
**Inputs**
echo_list
List of file names for all echos of interest