Skip to content

Instantly share code, notes, and snippets.

View WarrenWeckesser's full-sized avatar

Warren Weckesser WarrenWeckesser

View GitHub Profile
@WarrenWeckesser
WarrenWeckesser / mls_lfilter.py
Last active August 29, 2015 14:00
Scratch work for an impementation of a Maximum Length Sequence generator.
# Scratch work for Maximum Length Sequence calculations.
import numpy as np
from scipy.signal import lfilter, lfiltic
# These are definitions of linear shift register taps for use in mls()
_mls_taps = {2: [1], 3: [2], 4: [3], 5: [2], 6: [5], 7: [6], 8: [7, 6, 1],
9: [5], 10: [7], 11: [9], 12: [11, 10, 4], 13: [12, 11, 8],
14: [13, 12, 2], 15: [14], 16: [15, 13, 4], 17: [14],
@WarrenWeckesser
WarrenWeckesser / pz_match.py
Created November 21, 2014 05:05
Pole-zero matching scratch work
import numpy as np
from scipy.signal.filter_design import _cplxreal
def pop_real(p):
"""Pop the first real value in the list p."""
k = 0
while k < len(p) and p[k].imag != 0:
k += 1
if k == len(p):
@WarrenWeckesser
WarrenWeckesser / data.py
Created January 22, 2012 17:00
Modifed version of scipy/sparse/data.py adds numpy unary ufuncs to the _data_matrix class.
"""Base class for sparse matrice with a .data attribute
subclasses must provide a _with_data() method that
creates a new matrix with the same sparsity pattern
as self but with a different data array
"""
__all__ = []
@WarrenWeckesser
WarrenWeckesser / drag_tool_demo.py
Created October 11, 2012 21:01
A script to experiment with enable's DragTool.
from enable.api import Component, ComponentEditor
from enable.tools.api import DragTool
from traits.api import HasTraits, Instance
from traitsui.api import View, UItem
class MyDragTool(DragTool):
end_drag_on_leave = True
@WarrenWeckesser
WarrenWeckesser / erlang.py
Created May 23, 2013 17:19
Alternative implementation of the erlang distribution
import numpy as np
from scipy.stats.distributions import gamma_gen
class erlang_gen(gamma_gen):
def _argcheck(self, a):
good = (a > 0) & (np.floor(a) == a)
if not np.all(good):
@WarrenWeckesser
WarrenWeckesser / erlang2.py
Last active December 18, 2015 03:08
Alternative scipy erlang class, take 2
import warnings
import numpy as np
from scipy.stats.distributions import gamma_gen, rv_continuous
class erlang_gen(gamma_gen):
"""An Erlang continuous random variable.
%(before_notes)s
from __future__ import print_function, division
import time
import numpy as np
from numpy import convolve as np_convolve
from scipy.signal import convolve as sig_convolve, fftconvolve, firwin
from scipy.ndimage import convolve1d
from pylab import grid, show, legend, loglog, xlabel, ylabel, figure
@WarrenWeckesser
WarrenWeckesser / special_errors.txt
Created August 2, 2013 15:26
Test failures in scipy.special
This file has been truncated, but you can view the full file.
.................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................KFKFKK.K.....K...........K...KKKSF..KSSKKKKKSK..K...S..SFKKKSKKKKKKK..K........................................................
======================================================================
FAIL: test_mpmath.TestSystematic.test_chebyt_int
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/warren/anaconda/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/home/warren/a
@WarrenWeckesser
WarrenWeckesser / special-test-output.txt
Created August 23, 2013 23:29
Output of scipy.special tests
.................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................K.K..F.K.....K...........K...KKKS...KSSKKKKKSK..K...S..S.KKKSKKKKKK.............................................................
======================================================================
FAIL: test_mpmath.TestSystematic.test_ci
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/warren/anaconda/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/home/warren/anaconda
# File: animated_gif_writer.py
# Author: Warren Weckesser
# License: BSD 2-Clause (http://opensource.org/licenses/BSD-2-Clause)
#
# Copyright (c) 2015, Warren Weckesser
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#