Skip to content

Instantly share code, notes, and snippets.

View tsalo's full-sized avatar
🏠
Working from home

Taylor Salo tsalo

🏠
Working from home
View GitHub Profile
@tsalo
tsalo / getCodeDir.m
Last active August 29, 2015 14:16
Get directory of script. Add to the beginning of a script to help you load files in the same directory as the script. Makes projects more portable.
codeFile = mfilename('fullpath');
[codeDir, ~] = fileparts(codeFile);
codeDir = [codeDir '/'];
@tsalo
tsalo / cleanPath.m
Created March 10, 2015 19:48
Removes extra slashes from path string.
function fixedPath = cleanPath(inPath)
% FORMAT fixedPath = cleanPath(inPath)
% Removes extra slashed from inPath.
[filePath, fileName, fileSuffix] = fileparts(inPath);
if isempty(fileSuffix)
splitFile = regexp(filePath, '/', 'split');
else
splitFile = regexp(inPath, '/', 'split');
@tsalo
tsalo / get_code_dir.py
Last active August 29, 2015 14:17
Get directory of script. Also, get parent directory. Add to the beginning of a script to help you load files in the same directory as the script. Makes projects more portable.
"""
Get directory of script. Also, get parent directory.
"""
import os.path
code_dir = os.path.dirname(__file__)
par_dir = os.path.abspath(os.path.join(code_dir, os.path.pardir))
@tsalo
tsalo / allFilesExist.m
Created April 29, 2015 23:57
Check if all files in cell array exist.
function log = allFilesExist(cellArray)
log = all(cellfun(@(X) logical(exist(X, 'file')), cellArray));
end
% Dir results to cell array of file names
AllTextFiles = dir('/home/tsalo/*.txt');
cellArray = struct2cell(AllTextFiles);
cellArray = cellArray(1, :);
[allFilepaths, allFilenames, allSuffixes] = cellfun(@(X) fileparts(X), cellArray, 'UniformOutput', false);
@tsalo
tsalo / assign_intendedfor.py
Created April 18, 2017 21:39
Add "IntendedFor" field to BIDS field map jsons for the associated fMRI and DWI scans based on acquisition time.
import json
import bisect
from glob import glob
from os.path import join, splitext
from bids.grabbids import BIDSLayout
from dateutil.parser import parse
# subj_dir *must* have trailing /
subj_dir = '/scratch/tsalo006/dset/sub-01/'
sess = '01'
from nipype.interfaces.base import Bunch
from nipype.algorithms import modelgen
from copy import deepcopy
def lss(bunch_list):
"""Takes input Bunch list and returns list of Bunch lists with LSS regressors.
"""
all_infos = []
other_items = ['durations', 'amplitudes',
@tsalo
tsalo / tedana_decision_tree_pseudocode.py
Last active November 6, 2019 14:21
Some pseudocode implementing a tedana decision tree node according to a proposed specification.
from textwrap import dedent
import logging
LGR = logging.getLogger(__name__)
def list_to_str(lst, joiner='and'):
if len(lst) == 1:
return lst[0]
elif len(lst) == 2:
@tsalo
tsalo / nimare_atlas_decoding.ipynb
Created June 17, 2020 19:44
Decoding an atlas with NiMARE v0.0.3
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tsalo
tsalo / collect_fmriprep.py
Last active August 18, 2021 23:19
A short script to collect echo-wise processed files from an fMRIPrep working directory.
"""
Collect native-space preprocessed data from fMRIPrep working directory and
copy into fMRIPrep derivatives directory, in BIDS format.
This script has only been tested on fMRIPrep v20.2.1.
It may not work with other versions.
Written by Julio Peraza (@JulioAPeraza)
"""
import argparse