Skip to content

Instantly share code, notes, and snippets.

View SherazKhan's full-sized avatar

Sheraz Khan SherazKhan

  • Massachusetts General Hospital (MGH), Harvard Medical School and Massachusetts Institute of Technology (MIT)
  • Boston
  • X @dr_sheraz
View GitHub Profile
@SherazKhan
SherazKhan / dcor.py
Created June 20, 2017 23:42 — forked from kailashbuki/dcor.py
Computes the distance correlation between two matrices in Python.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Computes the distance correlation between two matrices.
https://en.wikipedia.org/wiki/Distance_correlation
"""
import numpy as np
from scipy.spatial.distance import pdist, squareform
@SherazKhan
SherazKhan / distcorr.py
Created June 20, 2017 23:43 — forked from wladston/distcorr.py
Distance correlation with p-value
from scipy.spatial.distance import pdist, squareform
import numpy as np
import random
import copy
def distcorr(Xval, Yval, pval=True, nruns=500):
""" Compute the distance correlation function, returning the p-value.
Based on Satra/distcorr.py (gist aa3d19a12b74e9ab7941)
import mne
import os
import numpy as np
import os.path as op
from mne.datasets import sample
from nose.tools import assert_equal
data_path = sample.data_path()
import itertools
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
from matplotlib.collections import PatchCollection
import numpy as np
def main():
fig = plt.figure()
ax = fig.add_subplot(111, projection='polar')
x = np.radians(np.arange(0, 360, 10))
@SherazKhan
SherazKhan / merge_eeg_meg.py
Created December 4, 2017 16:41
MEG MEG and EEG files in single fif file
import pyimpress
import mne
import numpy as np
from mne import create_info
from mne.io import RawArray
mff_fname='/cluster/transcend/sheraz/data/MEG_EEG/EEG/taskforce_1_vis_20160310_063855.mff'
# mff is the class supporting mff io
function sol = apply_inverse_raw(fname_raw,fname_inv,tmin, tmax, sel, nave,dSPM,pickNormal)
if ~exist('pickNormal','var')
pickNormal=0;
end
if ~exist('dSPM','var')
# Load 'pwr' package
library(pwr)
# 80% power
# Small effect size
small80p <- pwr.t.test(sig.level = 0.05, d = 0.2,
power = 0.8, type="two.sample", alternative="two.sided")
small80p
@SherazKhan
SherazKhan / plot_brainstorm_data.m
Created June 14, 2018 14:18 — forked from ftadel/plot_brainstorm_data.m
Calling MNE-Python in Matlab scripts
function plot_brainstorm_data()
% ============================
% Brainstorm tutorial datasets
% ============================
%
% Here we compute the evoked from raw for the Brainstorm
% tutorial dataset. For comparison, see [1]_ and:
%
% http://neuroimage.usc.edu/brainstorm/Tutorials/MedianNerveCtf
%
import mne
import numpy as np
def labels2stc(labels,labels_data,stc):
stc_new = stc.copy()
stc_new.data.fill(0)
for index,label in enumerate(labels):
if labels_data.ndim==1:
if isinstance(label, str):
temp = stc.in_label(mne.read_label(label))
function [cortex] = raw_cortex(data,fname_inv,nave,dSPM,pickNormal)
% data : 3D Matrix Channels x times x epochs
% fname_inv : Inverse operator file name
% nave : number of trials (for single trial should be one)
% dSPM : 0 or 1
% pickNormal : 0 (loose) or 1 (fixed)
if ~exist('pickNormal','var')
pickNormal=0;