Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# good discussion here: http://stackoverflow.com/questions/4308168/sigmoidal-regression-with-scipy-numpy-python-etc | |
# curve_fit() example from here: http://permalink.gmane.org/gmane.comp.python.scientific.user/26238 | |
# other sigmoid functions here: http://en.wikipedia.org/wiki/Sigmoid_function | |
import numpy as np | |
import pylab | |
from scipy.optimize import curve_fit | |
def sigmoid(x, x0, k): | |
y = 1 / (1 + np.exp(-k*(x-x0))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def makeGaussian(size, fwhm = 3, center=None): | |
""" Make a square gaussian kernel. | |
size is the length of a side of the square | |
fwhm is full-width-half-maximum, which | |
can be thought of as an effective radius. | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PREFIX=$HOME | |
VERSION=1.2.3 | |
# Install Protocol Buffers | |
wget http://protobuf.googlecode.com/files/protobuf-2.4.1.tar.bz2 | |
tar -xf protobuf-2.4.1.tar.bz2 | |
cd protobuf-2.4.1 | |
./configure --prefix=$PREFIX | |
make | |
make install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scipy | |
def plot_mean_and_sem(array, axis=1): | |
mean = array.mean(axis=axis) | |
sem_plus = mean + scipy.stats.sem(array, axis=axis) | |
sem_minus = mean - scipy.stats.sem(array, axis=axis) | |
fill_between(np.arange(mean.shape[0]), sem_plus, sem_minus, alpha=0.5) | |
plot(mean) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def histeq(im,nbr_bins=256): | |
#get image histogram | |
imhist,bins = np.histogram(im.flatten(),nbr_bins,normed=True) | |
cdf = imhist.cumsum() #cumulative distribution function | |
cdf = 255 * cdf / cdf[-1] #normalize | |
#use linear interpolation of cdf to find new pixel values | |
im2 = np.interp(im.flatten(),bins[:-1],cdf) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scipy.signal import butter, lfilter | |
def butter_bandpass_filter(data, lowcut, highcut, fs, order=5): | |
nyq = 0.5 * fs | |
low = lowcut / nyq | |
high = highcut / nyq | |
b, a = butter(order, [low, high], btype='band') | |
y = lfilter(b, a, data) | |
return y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def gaussian(self, height, center_x, center_y, width_x, width_y, rotation): | |
"""Returns a gaussian function with the given parameters""" | |
width_x = float(width_x) | |
width_y = float(width_y) | |
rotation = np.deg2rad(rotation) | |
center_x = center_x * np.cos(rotation) - center_y * np.sin(rotation) | |
center_y = center_x * np.sin(rotation) + center_y * np.cos(rotation) | |
def rotgauss(x,y): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tables | |
import numpy as np | |
# Store "all_data" in a chunked array... | |
# from: http://stackoverflow.com/questions/8843062/python-how-to-store-a-numpy-multidimensional-array-in-pytables | |
f = tables.openFile('all_data.hdf', 'w') | |
atom = tables.Atom.from_dtype(all_data.dtype) | |
filters = tables.Filters(complib='blosc', complevel=5) | |
ds = f.createCArray(f.root, 'all_data', atom, all_data.shape, filters=filters) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PySide import QtCore, QtGui | |
import sys | |
matplotlib.rcParams['backend.qt4']='PySide' | |
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas | |
from matplotlib.figure import Figure | |
class MatplotlibWidget(FigureCanvas): | |
def __init__(self, parent=None): |
NewerOlder