Instantly share code, notes, and snippets.

# Thomas A Caswell tacaswell

Created Jul 4, 2012 — forked from sixtenbe/analytic_wfm.py
Peak detection in Python
View .gitignore
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
 *.pyc
Last active Aug 9, 2022
factory for adding zoom callback to matplotlib graphs
View simp_zoom.py
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 matplotlib.pyplot as plt def zoom_factory(ax,base_scale = 2.): def zoom_fun(event): # get the current x and y limits cur_xlim = ax.get_xlim() cur_ylim = ax.get_ylim() # set the range cur_xrange = (cur_xlim[1] - cur_xlim[0])*.5
Created Oct 29, 2012
A simple function that implements rotation by Euler angles.
View euler_rot.py
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 euler_rot(XYZ,phi,theta,psi): '''Returns the points XYZ rotated by the given euler angles''' ERot = np.array([[np.cos(theta)*np.cos(psi), -np.cos(phi)*np.sin(psi) + np.sin(phi)*np.sin(theta)*np.cos(psi), np.sin(phi)*np.sin(psi) + np.cos(phi)*np.sin(theta)*np.cos(psi)], [np.cos(theta)*np.sin(psi), np.cos(phi)*np.cos(psi) + np.sin(phi)*np.sin(theta)*np.sin(psi),
Created Jan 16, 2013
A quick class for binding keys to step through an iterable in matplotlib
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
 class push_to_advance(object): def __init__(self): self.fig = plt.figure() self.ax = self.fig.gca() self.bound_keys = [] self.bound_cid = {} def add_step_through(self, gen, key): key = key[0] # make a single char if key in self.bound_keys:
Created Jan 17, 2013
Format nicely printed labels based on pi for matplotlib x-axis
View pi_format.py
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 format_frac(fr): '''Convert a/b to latex''' sp = str(fr).split('/') if len(sp) == 1: return sp[0] else: return r'$\frac{%s}{%s}$' % tuple(sp) frac_size = 4
Created Jan 24, 2013
A short example of how to override sys.excepthook to get exception out of pyqt
View qt_exception_decorator.py
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 PyQt4 import QtGui import time #app = QtGui.QApplication([]) class exception_munger(object): def __init__(self): self.flag = True self.txt = '' self.type = None def indicate_fail(self,etype=None, txt=None):
Last active Dec 15, 2015
bouncy annotated scatter plot
View gist:5329385
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 networkx as nx N = 15 scatter_data = rand(3, N) ** 2 G=nx.Graph() data_nodes = [] init_pos = {} for j, b in enumerate(scatter_data.T): x, y, _ = b
Last active Dec 16, 2015
Small helper program for extracting the meta-data from metamorph generated tifs
View md2txt
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/python #Copyright 2009-2013 Thomas A Caswell #tcaswell@uchicago.edu #http://jfi.uchicago.edu/~tcaswell # #This program is free software; you can redistribute it and/or modify #it under the terms of the GNU General Public License as published by #the Free Software Foundation; either version 3 of the License, or (at #your option) any later version.
Created Aug 2, 2013
Line2D handler which lets you tweak the x location of the markers.
View handler_xoffset.py
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 matplotlib.legend_handler import HandlerLine2D class HandlerXoffset(HandlerLine2D): def __init__(self, marker_pad=0.3, numpoints=1, x_offset=0, **kw): HandlerLine2D.__init__(self, marker_pad=marker_pad, numpoints=numpoints, **kw) self._xoffset = x_offset def get_xdata(self, legend, xdescent, ydescent, width, height, fontsize): numpoints = self.get_numpoints(legend) if numpoints > 1:
Last active Dec 21, 2015
Tweaked version of code at http://mail.scipy.org/pipermail/scipy-user/attachments/20060803/ad246212/attachment.py with minor bug fix and improved documentation.
View hough.py
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
 ## Copyright (C) 2006 Stefan van der Walt ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are ## met: ## ## 1. Redistributions of source code must retain the above copyright ## notice, this list of conditions and the following disclaimer. ## 2. Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in