Skip to content

Instantly share code, notes, and snippets.

View TomDLT's full-sized avatar

Tom Dupré la Tour TomDLT

View GitHub Profile
from functools import wraps
import time
import numpy as np
import scipy.sparse as sp
from sklearn.utils.testing import assert_array_equal
class ContextDecorator(object):
from functools import wraps
import time
import numpy as np
import scipy.sparse as sp
from sklearn.utils.testing import assert_array_equal
class ContextDecorator(object):
@TomDLT
TomDLT / surface3d_demo.py
Created January 5, 2018 14:05
2018 3D plotting challenge
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rcParams
from matplotlib.ticker import LinearLocator
# use default Latex font for math even with matplotlib 2.0
rcParams['mathtext.fontset'] = 'cm'
fig = plt.figure()
import cProfile
def profile_this(fn):
def profiled_fn(*args, **kwargs):
filename = fn.__name__ + '.profile'
prof = cProfile.Profile()
ret = prof.runcall(fn, *args, **kwargs)
prof.dump_stats(filename)
return ret
@TomDLT
TomDLT / example_peak_finder.py
Last active July 11, 2016 09:45
Some examples of the peak_finder function in MNE-python
import numpy as np
import matplotlib.pyplot as plt
from mne.preprocessing.peak_finder import peak_finder
def test_peak_finder(signal, thresh=None):
plt.plot(signal)
# find the maxima
from __future__ import print_function
import sys
import time
# copy from MNE-Python
class ProgressBar():
"""Class for generating a command-line progressbar
Parameters
----------
@TomDLT
TomDLT / smr2mne.py
Created March 25, 2016 12:08
Load Spike2 files (.smr) to MNE-Python objects
from __future__ import print_function
import warnings
import numpy as np
import neo.io
from mne.io.array import RawArray
from mne import create_info
def _smr(filename):
from sklearn.datasets import fetch_olivetti_faces
from sklearn.decomposition.nmf import NMF
from sklearn.externals.joblib import Parallel, delayed
def fit(X):
nmf.fit(X)
def nmf_test(n_jobs=-1, backend='multiprocessing'):
import warnings
import neo.io
def smr2sig(filename, smr_nums=[0]):
"""
read signal from .smr file (Spike2)
parameters
----------
filename : name of file