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 / png2pdfslides.sh
Created November 3, 2020 18:20
Crop and convert a bunch PNG into a merged PDF (riping slides from screenshots of zoom call for example)
echo "usage: png2pdfslides.sh FOLDER_WITH_PNG CROP_WIDTH by CROP_HEIGHT CROP_OFFSETX CROP_OFFSETX"
echo "output: merged.pdf in FOLDER_WITH_PNG"
echo " "
# This script converts PNG screenshots into a compiled PDF using file name ordering (presumably corresponding to timestamp if consecutive screenshots)
# 1) Goes into folder $MAINF
# 2) Crops an $WIDTH by $HEIGHT region for each PNG starting with a $OFFSETX pixels offset from the left and a OFFSETY pixels offset from the top
# 3) Converts each croped PNG to JPEG2000 for lossless PDF embedding
# 4) Converts each JPEG2000 to PDF
# 5) Merges all the PDFs together into one merged.pdf
# Crossing tissues sensitivity estimation
import numpy as np
# D1, D2, D3, the tissues diffusivities
# assumes D1 >= D2=D3
# comment and uncomment as needed
# um^2 / ms
MD = 0.14
@mpaquette
mpaquette / compute_mean_b.py
Created November 8, 2018 16:08
Compute mean b-value from voxelwise btable (output of compute_spatial_btable.py).
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import nibabel as nib
import argparse
DESCRIPTION = """
Compute mean b-value from voxelwise btable (output of compute_spatial_btable.py).
@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
@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 / 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 / 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 / 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 / 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 = """
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