This file contains hidden or 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 hidden or 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 cPickle as pickle | |
| def save(obj, filename): | |
| """Simple wrapper to pickle an object on disk | |
| :param: obj, any pickable object | |
| :param: filename, string representation of the file to save to | |
| """ | |
| with open(filename, 'wb') as f: |
This file contains hidden or 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 | |
| import matplotlib.pyplot as plt | |
| def plot_array(npArray, axis=1, xlim=None, ylim=None): | |
| plt.figure() | |
| num_plots = npArray.shape[axis] | |
| side = np.ceil(np.sqrt(num_plots)) | |
| for current_plot in range(1, num_plots+1): |
This file contains hidden or 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.optimize import curve_fit | |
| def exponential(t, A, tau, C): | |
| return A * np.exp(-tau * t) + C | |
| start = None # redefine | |
| ydata = data[start:] | |
| xdata = np.arange(ydata.shape[0]) | |
This file contains hidden or 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 peakSort(values): | |
| values = np.array(values) | |
| low = np.floor(values.shape[0] / 2) | |
| high = low+1 | |
| new = np.zeros_like(values) | |
| for i, item in enumerate(np.sort(values)[::-1]): | |
| if i % 2: | |
| new[high] = np.argwhere(values==item) | |
| high += 1 |
This file contains hidden or 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 lifetimeSparseness(data): | |
| N = data.shape[0] | |
| top = (np.power(np.sum(data/N), 2)) | |
| bottom = np.sum(np.power(data, 2) / N) | |
| return (1 - top / bottom) |
This file contains hidden or 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))) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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
| on open dropped_dir | |
| tell application "Terminal" | |
| set dirname to do shell script "perl -e \"print quotemeta ('" & POSIX path of item 1 of dropped_dir & "');\"" | |
| do script "cd " & dirname & "; ipython notebook --pylab; exit" | |
| end tell | |
| end open |
This file contains hidden or 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
| # found here: http://stackoverflow.com/questions/1589706/iterating-over-arbitrary-dimension-of-numpy-array | |
| import numpy as np | |
| def iterdim(a, axis=0) : | |
| a = np.asarray(a); | |
| leading_indices = (slice(None),)*axis | |
| for i in xrange(a.shape[axis]) : | |
| yield a[leading_indices+(i,)] | |