Skip to content

Instantly share code, notes, and snippets.

View ofgulban's full-sized avatar

Omer Faruk Gulban ofgulban

View GitHub Profile
@ofgulban
ofgulban / lasso_example.py
Created November 12, 2016 13:41
a simple example for matplotlib's lasso widget
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import LassoSelector
from matplotlib import path
fig = plt.figure()
ax1 = fig.add_subplot(121)
ax1.set_title('lasso selection:')
ax1.plot()
ax1.set_xlim([0, 10])
@ofgulban
ofgulban / minc_to_nifti.py
Created November 12, 2016 13:47
Convert MINC files to Nifti using nibabel.
"""Convert minc to nifti format."""
import os
import numpy as np
from nibabel import load, save, Nifti1Image
minc = load("/path/to/file.mnc.gz")
basename = minc.get_filename().split(os.extsep, 1)[0]
affine = np.array([[0, 0, 1, 0],
import numpy as np
cimport numpy as np
cimport cython
@cython.boundscheck(False)
@cython.wraparound(False)
cpdef cython_lstsqr(x_ary, y_ary):
""" Computes the least-squares solution to a linear matrix equation. """
cdef double x_avg, y_avg, var_x, cov_xy,\
slope, y_interc
@ofgulban
ofgulban / freesurfer_label_operations.py
Created November 14, 2016 15:49
Add Freesurfer labels from different subjects in the average mesh (fsaverage).
"""Add freesurfer labels similar to 'fslmaths -add'.
Use an .mgh file to read relevant information such as headers or number of
vertices.
Note: Freesurfer operations can be performed on .mgh format without
getting unrecognized data type error.
"""
import numpy as np
@ofgulban
ofgulban / sort_4D_nifti.py
Last active March 17, 2017 16:59
Sort 4D nifti files to get minimum/maximum intensity volume projections.
"""Example for sorting 4D nifti data."""
import numpy as np
import os
from nibabel import load, save, Nifti1Image
from __future__ import division
nii = load('/path/to/your/4D_nifti_file.nii.gz')
basename = nii.get_filename().split(os.extsep, 1)[0]
niiHeader = nii.header
@ofgulban
ofgulban / psychopy_conda_installation_notes.md
Last active November 18, 2016 19:25
Notes about installing psychopy(1.84.2) with conda. Can be useful for people who wants to use minimal amount of packages develop psychopy scripts instead of the standalone installation.

Some terms

Anaconda: full distributor for python packages, uses only conda.
Miniconda: stripped down version of anaconda containing only the bare minimum packages (can use both conda and pip).
conda: a package manager.
pip: another package manager.


To be able to run Psychopy(1.84.2) from Conda with Spyder you need to follow these steps:

@ofgulban
ofgulban / powermate_pyusb_example.py
Last active January 4, 2017 15:12
An example script showing how to interact with Griffin Powermate using pyusb library.
"""Pyusb with Griffin Powermate.
Linux notes:
On Debian 8 it requires admin rights to access the powermate device.
The script can be tested via activating superuser and the virtual
environment with pyusb and calling the script.
Usage notes:
dev.read returns the following values in an array:
0: button state (0 not pressed, 1 pressed)
"""Test Griffin Powermate library using pywinusb."""
from griffin_powermate import GriffinPowermate
def rotation_listener(data):
"""Print powermate input only for rotation."""
global dial_click
if data[1] == 1 :
dial_click = True
@ofgulban
ofgulban / v16_to_nii.m
Last active December 10, 2016 10:09
Convert .v16 data to nifti using Neuroelf.
% Convert VMR files with uint16 precision (.v16) using neuroelf.
%
% v16 files are better than vmr files for nifti conversion because
% because the intensity values are not limited to the small range of
% 0 to 255 integers.
%
% http://neuroelf.net/
[fileName, pathName] = uigetfile('.v16');
vmr = xff(fullfile(pathName, fileName));
@ofgulban
ofgulban / bv_fmr_creation.js
Last active December 22, 2016 18:38
Brainvoyager scripting example for creating fmr files.
// Batch script for cretaing FMR files from renamed dicom files (.dcm).
//
// You need to create the subfolders in the main data path beforehand.
// For instance: /path/to/your/subject/RUN_1
// /path/to/your/subject/RUN_2
// ...
//
// For more information, check the scripting guide:
// http://support.brainvoyager.com/automation-aamp-development/46-writing-scripts/133-scripting-reference-guide.html