Skip to content

Instantly share code, notes, and snippets.

@trigfa
trigfa / peakdetect.py
Created August 28, 2013 13:28
Simple peak detection in python. I'm not sure where this came from although originally it was obviously written in Matlab by Eli Billauer. I think I had to change a single line to add the import of asarray from numpy
import sys
from numpy import NaN, Inf, arange, isscalar, array, asarray
def peakdet(v, delta, x = None):
"""
Converted from MATLAB script at http://billauer.co.il/peakdet.html
Returns two arrays
function [maxtab, mintab]=peakdet(v, delta, x)
@trigfa
trigfa / imagedisplay
Last active December 23, 2015 12:39
Displaying a dicom image in a matplotlib widget within a pyqt window. The axes have been set to not visible
class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self,parent=None):
QDialog.__init__(self,parent)
self.setupUi(self)
self.mpl.canvas.ax.clear()
ds=dicom.read_file("slice.dcm")
#self.mpl.canvas.ax.imshow(self.image1, cmap=pylab.cm.bone)
self.mpl.canvas.ax.imshow(ds.pixel_array, cmap=pylab.cm.bone)
self.mpl.canvas.ax.xaxis.set_visible(False)
@trigfa
trigfa / matplotlib_plot.py
Created September 25, 2013 15:22
matplotlib plotting
self.cal_curve_widget.canvas.ax.clear()
self.cal_curve_widget.canvas.ax.plot(self.cal_MU,self.cal_density)
self.cal_curve_widget.canvas.draw()
@trigfa
trigfa / exists?
Created September 27, 2013 11:09
Check if a filename exist in python
try:
with open('filename'): pass
except IOError:
print 'Oh dear.'
@trigfa
trigfa / pyqt_print.py
Created November 18, 2013 20:42
Trying to print from pyqt
import sys
import numpy as np
from PyQt4.QtCore import *
from PyQt4.QtGui import *
#from xlwt import *
from pylab import plot, show
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar2
@trigfa
trigfa / noSpaces.py
Created December 19, 2013 16:42
Replaces spaces with underscores in file names. This script takes the directory name as an argument
#!/usr/bin/python
import os
import sys
files = os.listdir(sys.argv[1])
for f in files:
os.rename(f, f.replace(' ', '_'))
@trigfa
trigfa / .bashrc
Last active January 3, 2016 18:59
some useful aliases for ipython and ruby
#
# ~/.bashrc
#
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
alias designer='designer -qt=4'
alias python='python2'
alias ipython='ipython2'
{%- extends 'html_full.tpl' -%}
{% block input_group -%}
<div class="input_hidden">
{{ super() }}
</div>
{% endblock input_group %}
{%- block header -%}
{{ super() }}
import numpy as np
from math import pi, log
import pylab
from scipy import fft, ifft
from scipy.optimize import curve_fit
i = 10000
x = np.linspace(0, 3.5 * pi, i)
y = (0.3*np.sin(x) + np.sin(1.3 * x) + 0.9 * np.sin(4.2 * x) + 0.06 *
np.random.randn(i))
@trigfa
trigfa / gist:8f0b45d6f71fa3956ff5
Created December 4, 2015 09:16
Hide input cells and prompts in Jupyter notebook. Useful if using RISE for slideshow
%%HTML
<script>
var code_show=true; //true -> hide code at first
function code_toggle() {
$('div.prompt').hide(); // always hide prompt
if (code_show){
$('div.input').hide();
} else {