Skip to content

Instantly share code, notes, and snippets.

@chrisgorgo
chrisgorgo / function_workflow.py
Created October 8, 2014 16:32
function_workflow.py
import nipype.pipeline.engine as pe
from nipype.interfaces.utility import Function
def Hello():
import os
from nipype import logging
iflogger = logging.getLogger('interface')
message = "Hello "
iflogger.info(message)
return message
__author__ = 'lampe'
"""
=============================================
1. Registration of T1 to QSM
2. Apply the xfm to the masks that have been created with the T1, so they are in QSM space
=============================================
Packages and Data Setup
=======================
Import necessary modules from nipype.
from nilearn.plotting.img_plotting import plot_img
import pylab as plt
import nibabel as nb
import numpy as np
nii = nb.load("/home/raid3/gorgolewski/Downloads/fmap_field_masked.nii.gz")
print nii.get_affine()
scaling_affine = np.array([[-3, 0, 0, 0],
In [4]: !cat /tmp/stefan.py
out_name = "/tmp/bla"
out = open(out_name, 'w')
out.write("asdfasdfasdf\n") #out_str) out.close
out = open(out_name, 'w')
out.write("asdfasdfasdf\n")
out.close()
In [5]: %run /tmp/stefan.py
(devel)adenauer:~$ cd /tmp/
(devel)adenauer:/tmp$ git clone https://github.com/nipy/nipype.git
Cloning into 'nipype'...
remote: Reusing existing pack: 36611, done.
remote: Total 36611 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (36611/36611), 17.80 MiB | 1.13 MiB/s, done.
Resolving deltas: 100% (22184/22184), done.
(devel)adenauer:/tmp$ cd nipype/
(devel)adenauer:/tmp/nipype$ git remote
origin
@chrisgorgo
chrisgorgo / get_tr_and_sliceorder_from_dicoms.py
Last active December 30, 2015 11:19
A little function to get TR and slicetime order from dicoms
def get_tr_and_sliceorder(dicom_files, convention="SPM"):
import numpy as np
import dcmstack, dicom
my_stack = dcmstack.DicomStack()
for src_path in dicom_files:
src_dcm = dicom.read_file(src_path)
my_stack.add_dcm(src_dcm)
nii_wrp = my_stack.to_nifti_wrapper()
if convention == "french":
def partial_correlation_via_inverse(X):
model = GraphLassoCV()
model.fit(X)
prec_ = model.precision_
return -cov2corr( model.precision_ ) )
def cov2corr( A ):
"""
covariance matrix to correlation matrix.
"""
@chrisgorgo
chrisgorgo / gist:3911604
Created October 18, 2012 12:49
onsemaple TFCE
#merge maps - condition 1
fslmerge -t "/scr/adenauer1/workingdir/rs_analysis_group/main_workflow/merge_conn_maps_6_58_0/roi_6_58_0_masked_merged.nii.gz" /scr/namibia1/baird/MPI_Project/results/volumes/normalized_z_scored_corr_map/_subject_id_13261.8d/_roi_6.58.0/_fwhm_5/roi_6_58_0_masked.nii /scr/namibia1/baird/MPI_Project/results/volumes/normalized_z_scored_corr_map/_subject_id_14390.d3/_roi_6.58.0/_fwhm_5/roi_6_58_0_masked.nii /scr/namibia1/baird/MPI_Project/results/volumes/normalized_z_scored_corr_map/_subject_id_14446.fb/_roi_6.58.0/_fwhm_5/roi_6_58_0_masked.nii /scr/namibia1/baird/MPI_Project/results/volumes/normalized_z_scored_corr_map/_subject_id_16090.c9/_roi_6.58.0/_fwhm_5/roi_6_58_0_masked.nii /scr/namibia1/baird/MPI_Project/results/volumes/normalized_z_scored_corr_map/_subject_id_12184.55/_roi_6.58.0/_fwhm_5/roi_6_58_0_masked.nii /scr/namibia1/baird/MPI_Project/results/volumes/normalized_z_scored_corr_map/_subject_id_15070.25/_roi_6.58.0/_fwhm_5/roi_6_58_0_masked.nii /scr/namibia1/baird/MPI_Projec
Process: Python [6691]
Path: /opt/local/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
Identifier: Python
Version: 2.7.3 (2.7.3)
Code Type: X86-64 (Native)
Parent Process: Python [6670]
User ID: 501
Date/Time: 2012-09-27 19:40:00.297 +0200
OS Version: Mac OS X 10.8.2 (12C54)
def plot_coregistration():
anat_file = "/Users/filo/data/rs_pipeline/GSDT/anat/mprage.nii"
func_file = "/Users/filo/workdir/rs_preprocessing/preprocess/preproc/take_mean_art/weighted_mean/corr_rest_roi_dtype.nii.gz"
affine_file = '/Users/filo/workdir/rs_preprocessing/preprocess/preproc/getmask/register/mapflow/_register0/corr_rest_roi_dtype_bbreg_recon_all.mat'
from nipy.labs import viz
from nipy.labs.viz_tools import anat_cache
import nibabel as nb
anat = nb.load(anat_file).get_data()
anat_affine = nb.load(anat_file).get_affine()