Skip to content

Instantly share code, notes, and snippets.

Avatar

Thomas A Caswell tacaswell

  • Brookhaven National Lab
  • New York
View GitHub Profile
View meta_fun.py
import sys
sys.setrecursionlimit(10000)
class Meta(type):
def __new__(*args, **kwargs):
print('I will not use metaclasses just for the fun of using them', end=' ')
magic_count = kwargs.pop('__magic_count', 0)
if magic_count > 1000:
return type.__new__(*args, **kwargs)
Meta.__new__(__magic_count=magic_count+1, *args, **kwargs)
View pygotham_lightning_tacaswell.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View document.py
class Document(dict):
def __init__(self, name, *args, **kwargs):
self._name = name
super(Document, self).__init__(*args, **kwargs)
def __getattr__(self, key):
return self[key]
def __setattr__(self, key, value):
@tacaswell
tacaswell / .gitignore
Created Jul 4, 2012 — forked from sixtenbe/analytic_wfm.py
Peak detection in Python
@tacaswell
tacaswell / euler_rot.py
Created Oct 29, 2012
A simple function that implements rotation by Euler angles.
View euler_rot.py
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),
View so_interactive_demo.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View jsonschema_play.py
from jsonschema import validate
schema = {
"definitions": {
"data_key": {
"properties": {
"external": {
"type": "string",
"pattern": "^[A-Z]+:?"
},
@tacaswell
tacaswell / qt_exception_decorator.py
Created Jan 24, 2013
A short example of how to override sys.excepthook to get exception out of pyqt
View qt_exception_decorator.py
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):
@tacaswell
tacaswell / gist:5329385
Last active Dec 15, 2015
bouncy annotated scatter plot
View gist:5329385
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
@tacaswell
tacaswell / md2txt
Last active Dec 16, 2015
Small helper program for extracting the meta-data from metamorph generated tifs
View md2txt
#!/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.