Skip to content

Instantly share code, notes, and snippets.

View xgrg's full-sized avatar
🤖
gradient decent

Greg Operto xgrg

🤖
gradient decent
View GitHub Profile
@xgrg
xgrg / test
Created July 6, 2011 14:31
test
messages_defaults = [ ('process filepath',
'/home/grg/svn/brainvisa/t1mri/t1mri-gpl/trunk/brainvisa/toolboxes/t1mri\
/processes/segmentationpipeline/components04/segmentation/VipBiasCorrection.py') ]
for each in signature.keys():
messages_defaults.append( (each, instance.__getattribute__(each)) )
@xgrg
xgrg / catidb vs catishared comparison
Last active December 29, 2015 02:38
Compare files list on catishared and files for catidb
import os, string, catidb
rql = 'Distinct Any P WHERE FP is FileParameter, FP file F , F path P'
db = catidb.CatiDB('user', 'Passe, le mot.')
res = [e[0] for e in db.rql(rql)]
dbdir = '/neurospin/cati/cati_shared/MEMENTO'
totalfiles = []
for root, dirs, files in os.walk(dbdir):
if root.startswith(os.path.join(dbdir, 'ACTIONS')) or root.startswith(os.path.join(dbdir, 'study_data')): continue
@xgrg
xgrg / HTML Template example
Last active January 2, 2016 17:08
Formatting contents from a Python dictionary using a HTML template
<html>
<body>
<script type="text/javascript">
<!--
function toggle_visibility(id) {
var e = document.getElementById(id);
if(e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'block';
@xgrg
xgrg / OCD.ipynb
Last active February 10, 2016 13:47
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@xgrg
xgrg / map_csv_to_corticalROI.py
Last active February 24, 2016 15:24
Usage : ./map_csv_to_corticalROI.py -i lh.r.aparc.a2009s.annot.gii --csv stats.csv -o test.tex
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def map_values(parc, csv):
from soma import aims
import numpy as np
labels2009 = ['G_and_S_frontomargin', 'G_and_S_occipital_inf', 'G_and_S_paracentral', 'G_and_S_subcentral', 'G_and_S_transv_frontopol', 'G_and_S_cingul-Ant', 'G_and_S_cingul-Mid-Ant', 'G_and_S_cingul-Mid-Post', 'G_cingul-Post-dorsal', 'G_cingul-Post-ventral', 'G_cuneus', 'G_front_inf-Opercular', 'G_front_inf-Orbital', 'G_front_inf-Triangul', 'G_front_middle', 'G_front_sup', 'G_Ins_lg_and_S_cent_ins', 'G_insular_short', 'G_occipital_middle', 'G_occipital_sup', 'G_oc-temp_lat-fusifor', 'G_oc-temp_med-Lingual', 'G_oc-temp_med-Parahip', 'G_orbital', 'G_pariet_inf-Angular', 'G_pariet_inf-Supramar', 'G_parietal_sup', 'G_postcentral', 'G_precentral', 'G_precuneus', 'G_rectus', 'G_subcallosal', 'G_temp_sup-G_T_transv', 'G_temp_sup-Lateral', 'G_temp_sup-Plan_polar', 'G_temp_sup-Plan_tempo', 'G_temporal_inf', 'G_temporal_middle', 'Lat_Fis-ant-Horizont', 'Lat_Fis-ant-Vertical', 'Lat_Fis-post', '
from glob import glob
import pandas as pd
import os.path as osp
import os
import textwrap
def process(directory, excel_file, filename):
files = [osp.abspath(e) for e in glob(osp.join(directory, '*', '*', filename))]
wholeset = []
wholeset2 = []
@xgrg
xgrg / pano.py
Last active March 18, 2017 18:59
Converting a picture to a scrollable panorama in Facebook
#!/usr/bin/env python
import os
import os.path as osp
import sys
from PIL import Image
dim = {'120, 86':(6000,5343),
'150, 86':(6000, 4274),
'180, 86':(6000,3562),
'240, 86':(6000,2671),
@xgrg
xgrg / gist:d74133ae693fe98cd1a0dae58aace346
Last active May 31, 2017 11:04
Arithmetics on images with nibabel/numpy
import numpy as np
import nibabel as nib
im1 = nib.load('/tmp/path_to_image.nii.gz')
a = np.array(im1.dataobj)
im2 = nib.Nifti1Image(a/2.0, header=im1.header, affine=im1.affine)
im2.to_filename('/tmp/path_to_new_image.nii.gz')
def rescale(source, target):
import nibabel as nib
import numpy as np
from nilearn import image
n = nib.load(source)
d = np.array(n.dataobj)
s = n.dataobj.slope
i = image.new_img_like(n, d/s)
i.to_filename(target)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.