Skip to content

Instantly share code, notes, and snippets.

View tsbertalan's full-sized avatar

Tom Bertalan tsbertalan

  • University of Massachusetts Lowell
  • United States
View GitHub Profile
@tsbertalan
tsbertalan / .gitignore
Last active December 10, 2015 00:09
How to return a double * from swig as a Python list? Use a std::vector instead.
returnList.py
_returnList.so
*_wrap.cxx
# -*- coding: utf-8 -*-
from tomIntegrate import intor, randr
from matplotlib import pyplot as plt
from numpy import array, polyfit, log, exp
def dxdt(X, r=28.):
s = 10.
b = 8. / 3.
x = X[0]
y = X[1]
@tsbertalan
tsbertalan / randomInjection.py
Created April 18, 2013 14:50
diffusion with random source/sink injections ∂ θ(x, t) / ∂ t = ∇ 2 θ(x, t) + S(x,t)
from matplotlib import pyplot as plt
from matplotlib import colors
import numpy as np
from tomIntegrate import randr
from time import sleep
NX = NY = 64
figsize=(16, 16)
ptake = 0.001
pgive = 0.0004
@tsbertalan
tsbertalan / hussieHist.py
Last active December 16, 2015 17:59
Visualization of Andrew Hussie's output. The man is a fiend. See plot outputs at http://www.tombertalan.com/entries/single/102
import time
from datetime import datetime
import matplotlib.pyplot as plt
#get the csv lines as strings
lines = list(open('hussieout.csv'))
lines = lines[:-1] #remove final newline
#split each line on commas (hopefully there's only one per line)
lines = [line.split(',') for line in lines]
#remove whitespace at the ends of the elements (mostly--only?--just \n characters at the ends)
@tsbertalan
tsbertalan / qsub.py
Created October 25, 2013 18:44 — forked from astrofrog/qsub.py
import os
import random
import string
import tempfile
import subprocess
def random_id(length=8):
return ''.join(random.sample(string.ascii_letters + string.digits, length))
TEMPLATE_SERIAL = """
import numpy as np
import scipy.linalg
n = 130
r = np.array(np.random.normal(size=(n, n)), dtype=np.float32)
e = scipy.linalg.eig(r, left=False, right=False)
print e.mean()
import numpy as np
import scipy.linalg
n = 130
r = np.array(np.random.normal(size=(n, n)), dtype=np.float32)
e = scipy.linalg.eig(r, left=False, right=False)
print e.mean()
@tsbertalan
tsbertalan / bouncr.py
Created January 13, 2014 01:24
bouncing ball
'''
This example uses a MovieWriter directly to grab individual frames and
write them to a file. This avoids any event loop integration, but has
the advantage of working with even the Agg backend. This is not recommended
for use in an interactive setting.
This version avoids the ugly stateful plt.* expressions, and the
set_data method. Instead, it uses the more generic axis methods. This is slower,
but easier to remember, I hope.
'''
'''
Quick hack to combine two BibTeX files with truly indentical entries
into one monolithic file.
Someone else could write an argparse interface to make this more reusable.
For now, I just need to get back to work.
'''
from bibtexparser.bparser import BibTexParser
with open('math.bib', 'r') as bibfile:
'''
Quick hack to combine two BibTeX files with truly indentical entries
into one monolithic file.
Someone else could write an argparse interface to make this more reusable.
For now, I just need to get back to work.
'''
from bibtexparser.bparser import BibTexParser
with open('math.bib', 'r') as bibfile: