Skip to content

Instantly share code, notes, and snippets.

View mpaquette's full-sized avatar

Michael Paquette mpaquette

  • Leipzig, Germany
View GitHub Profile
@mpaquette
mpaquette / dsi_parameters_paper_fig_6_7.py
Last active October 7, 2016 03:11
Small script that fetch DSI data and uses Dipy recon module to recreate figure 6 and 7 from Paquette et al. "Optimal DSI reconstruction parameter recommendations: better ODFs and better connectivity".
#!/usr/bin/env python
"""
This example reproduces the ODFs in figure 6 and 7 from Paquette et al.
"Optimal DSI reconstruction parameter recommendations: better ODFs and better connectivity".
The Optimal DSI (figure 7), is obtained using the parameters from the last
line of Tbl. 5 as the snr was estimated at 38 following an approach detailed
in https://github.com/nipy/dipy/blob/master/doc/examples/snr_in_cc.py
Required python modules (with their respective reqs):
@mpaquette
mpaquette / signal_multi_shell.py
Last active August 27, 2015 21:13
Dirty example to display signal for individual shell of multi-shell as spherical function.
"""
Dirty example to display signal for individual shell of multi-shell as spherical function.
No background maps, just signal spheres.
Option to assume or not antipodal symmetry.
Assume the gradient table as at least 1 b0.
Uses so not very robust ad-hoc function to detect which sample belong to which shell.
"""
import numpy as np
@mpaquette
mpaquette / resample_dwi_signal.py
Created February 16, 2016 22:16
Resample DWI signal single-shell
import numpy as np
import nibabel as nib
# shitty way to get 1 voxel of single-shell signal
from dipy.data import fetch_isbi2013_2shell, read_isbi2013_2shell
fetch_isbi2013_2shell()
img, gtab = read_isbi2013_2shell()
data = img.get_data()
del img
import sys
import numpy as np
import nibabel as nib
import tractconverter as tc
from dipy.tracking.streamlinespeed import length, set_number_of_points
from dipy.tracking.vox2track import track_counts
@mpaquette
mpaquette / vol_rand_parc.py
Created December 15, 2017 18:31
Parcellate volume data into N random parcel using floodfill to preserve connectivity.
import argparse
import numpy as np
import nibabel as nib
from scipy.spatial.distance import pdist, squareform
DESCRIPTION = """
@mpaquette
mpaquette / vol_rand_parc_fast.py
Created December 15, 2017 18:33
Parcellate volume data into N random parcel using kmeans.
import argparse
import numpy as np
import nibabel as nib
import sklearn.cluster as clu
DESCRIPTION = """
@mpaquette
mpaquette / rot_bvecs_ants.py
Created August 29, 2018 11:44
Rotate bvecs with ANTS transform matrix
from scipy.io import loadmat
import numpy as np
import sys
if __name__ == "__main__":
print('input_ants_rigid_transform input_bvecs output_bvec')
# Loading Ants transform
trans = loadmat(sys.argv[1])
matrice = trans['AffineTransform_double_3_3'][:9].reshape((3,3))
@mpaquette
mpaquette / resample_nifti.py
Created August 30, 2018 12:17
Simple script to downsample niftis.
#!/usr/bin/env python
import numpy as np
import nibabel as nib
import sys
def main(input, output, dx, dy, dz):
img = nib.load(input)
data = img.get_data()
downsampling_factor = np.array([int(dx), int(dy), int(dz)])
print('Input image is size {} {} {}'.format(data.shape[0], data.shape[1], data.shape[2]))
@mpaquette
mpaquette / plotPubmed.py
Created September 13, 2018 18:34
Dirty Script to count and graph PubMed hits per year for specific search
import BeautifulSoup as bs
import requests
import pylab as pl
def countPubmed(searchterm, minyear, maxyear):
quer = '%20'.join(searchterm.split(' '))
N_res = []
y = []
for year in range(minyear, maxyear+1):
@mpaquette
mpaquette / compute_spatial_btable.py
Created November 8, 2018 15:54
Computes the voxelwise btable from initial bvecs/bvals and calc_grad_perc_dev output (from fullwarp output of gradunwrap.py)
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# first draft of script to compute voxelwise bvec and bval after GNL
# work on the output of calc_grad_perc_dev
# calc_grad_perc_dev works on the fullwarp output of gradunwrap.py
import numpy as np
import nibabel as nib
import argparse