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.optimize import curve_fit | |
def linear(x, m, b): | |
return m*x + b | |
x = np.arange(0,400,1) | |
y = linear(x, -0.2, 3) | |
yn = y + np.random.normal(size=len(x))*2 | |
yn[50:350] *= np.random.normal(size=300) |
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
// most recent update: 04/22/2014 | |
// one liner | |
javascript:function go(){var asdf = window.location.host.replace(/\./g, "-");window.location = window.location.protocol+'//'+asdf+'.ezp1.harvard.edu'+window.location.pathname+window.location.search;}go();void(0); | |
// expanded | |
function go() { | |
var asdf = window.location.host.replace(/\./g, "-"); // replace all the periods with dashes (uses regexp) | |
window.location = window.location.protocol+'//' + |
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
#!/usr/bin/env python | |
import subprocess | |
import time | |
import re | |
import os | |
import sys | |
# launch the server and get the jobid |
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 contiguous_regions(condition): | |
"""Finds contiguous True regions of the boolean array "condition". Returns | |
three 1d arrays: start indicies, stop indicies and lengths of contigous regions | |
""" | |
d = np.diff(condition) | |
idx, = d.nonzero() | |
idx += 1 # need to shift indices because of diff |
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 | |
import scipy.signal | |
import matplotlib.pyplot as plt | |
n=256 | |
data = np.random.random(n) | |
data_fft = np.fft.fft(data) | |
# see also : http://mpastell.com/2010/01/18/fir-with-scipy/ |
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
# imports | |
import numpy as np | |
import scipy as scipy | |
# construct static 2d distance tree | |
size = 256 | |
x, y = np.mgrid[0:size, 0:size] | |
distance_tree = spatial.KDTree(zip(x.ravel(), y.ravel())) | |
# simple use case |
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
# setup colormaps with alpha backgrounds | |
imshow(np.random.random((10,10)), cmap='Reds') | |
imshow(np.random.random((10,10)), cmap='Blues') | |
close('all') | |
import copy | |
red_alpha = copy.copy(mpl.cm.Reds) | |
blue_alpha = copy.copy(mpl.cm.Blues) |
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
{ | |
"metadata": { | |
"name": "replace text in files" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ |
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 mahotas | |
def excludePixels(image, size_cutoff=1): | |
labeled_image = mahotas.label(image)[0] | |
for label_id in range(labeled_image.max()+1): | |
label_id_index = labeled_image == label_id | |
if label_id_index.sum() <= size_cutoff: | |
labeled_image[label_id_index] = 0 |