Skip to content

Instantly share code, notes, and snippets.

View ChrisBeaumont's full-sized avatar

Chris Beaumont ChrisBeaumont

View GitHub Profile
@ChrisBeaumont
ChrisBeaumont / perseus_yt.py
Last active December 17, 2015 23:09
Rendering Perseus in yt
import numpy as np
import os
from yt.frontends.stream.api import load_uniform_grid
from yt.mods import ColorTransferFunction
from astropy.io import fits
from scipy.ndimage.measurements import label
from scipy.ndimage.morphology import binary_opening
def thresh(image, lo, hi):
"""
This test module exercises the IPython qt import logic using pytest
It should be run with PyQt4 and PySide installed, as
py.test test_ipython_qt.py --boxed
It requires pytest and pytest-xdist
"""
from subprocess import check_output
@ChrisBeaumont
ChrisBeaumont / pyside_menu_bug.py
Created February 14, 2013 23:27
The menu bar in this script doesn't display. It *does* display if QMenuBar is created without a reference to its parent. This bug has been reported at https://bugreports.qt-project.org/browse/PYSIDE-21?focusedCommentId=195277&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-195277
from PySide import QtCore, QtGui
app = QtGui.QApplication([''])
mw = QtGui.QMainWindow()
#mbar = QtGui.QMenuBar() # menu visible
mbar = QtGui.QMenuBar(mw) # menu not visible
menu = QtGui.QMenu(mbar)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ChrisBeaumont
ChrisBeaumont / workaround.py
Created January 10, 2013 02:06
Workaround linker issue when installing scikit-learn on a mac that uses macports
from subprocess import check_call
#remove build directory
check_call('rm -rf build'.split())
#compile and capture stdout
with open('build.log', 'w') as log:
check_call('python setup.py install --user'.split(), stdout=log)
log = open('build.log').read().splitlines()
@ChrisBeaumont
ChrisBeaumont / perseus.ipynb
Last active December 10, 2015 15:29
perseus_bg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ChrisBeaumont
ChrisBeaumont / dock.py
Created December 4, 2012 21:13
MPL set_cursor problem under 1.2.0
from PyQt4.QtGui import QApplication, QMainWindow, QDockWidget
from PyQt4.QtCore import Qt
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg
from matplotlib.backends.backend_qt4 import NavigationToolbar2QT
from matplotlib.figure import Figure
a = QApplication([''])
w = QMainWindow()
@ChrisBeaumont
ChrisBeaumont / mandel.py
Created November 16, 2012 20:37
interactive Mandelbrot numba example
"""From the numba examples
(https://github.com/numba/numba/blob/master/examples/mandel.py),
but tweaked to recalculate on the fly as the viewport changes"""
from numba import autojit
import numpy as np
from pylab import imshow, jet, show, ion
import matplotlib.pyplot as plt
from matplotlib import rcParams
rcParams['image.origin'] = 'lower'
@ChrisBeaumont
ChrisBeaumont / convert.pro
Created November 15, 2012 12:59
coordinate conversions
pro writecol, file, c1, c2
openw, lun, file, /get
for i = 0, n_elements(c1) - 1, 1 do begin
printf, lun, c1[i], c2[i], format='(d, ", ", d)'
endfor
free_lun, lun
end
pro generate_j2000_points
seed = 42
@ChrisBeaumont
ChrisBeaumont / cmap2pixmap.py
Created November 6, 2012 16:30
convert matplotlib colormap to Qt4 pixmap
from matplotlib import cm
import numpy as np
from PyQt4.QtGui import QImage, QPixmap, QColor
def cmap2pixmap(cmap, steps=50):
"""Convert a maplotlib colormap into a QPixmap
:param cmap: The colormap to use
:type cmap: Matplotlib colormap instance (e.g. matplotlib.cm.gray)