updated doctests

master
pbrod 9 years ago
parent 33367e4c71
commit 3bff71dfdd

@ -1,7 +1,7 @@
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from pylab import subplot, plot, title, figure from pylab import subplot, plot, title, figure
from numpy import random, arange, sin from numpy import random, arange, sin
from sg_filter import SavitzkyGolay, smoothn # calc_coeff, smooth from .sg_filter import SavitzkyGolay, smoothn # calc_coeff, smooth
def example_reconstruct_noisy_chirp(): def example_reconstruct_noisy_chirp():

@ -17,24 +17,27 @@ def magic(n):
Examples Examples
-------- --------
>>> magic(3) >>> np.allclose(magic(3),
array([[8, 1, 6], ... [[8, 1, 6],
[3, 5, 7], ... [3, 5, 7],
[4, 9, 2]]) ... [4, 9, 2]])
True
>>> magic(4)
array([[16, 2, 3, 13], >>> np.allclose(magic(4),
[ 5, 11, 10, 8], ... [[16, 2, 3, 13],
[ 9, 7, 6, 12], ... [ 5, 11, 10, 8],
[ 4, 14, 15, 1]]) ... [ 9, 7, 6, 12],
... [ 4, 14, 15, 1]])
>>> magic(6) True
array([[35, 1, 6, 26, 19, 24],
[ 3, 32, 7, 21, 23, 25], >>> np.allclose(magic(6),
[31, 9, 2, 22, 27, 20], ... [[35, 1, 6, 26, 19, 24],
[ 8, 28, 33, 17, 10, 15], ... [ 3, 32, 7, 21, 23, 25],
[30, 5, 34, 12, 14, 16], ... [31, 9, 2, 22, 27, 20],
[ 4, 36, 29, 13, 18, 11]]) ... [ 8, 28, 33, 17, 10, 15],
... [30, 5, 34, 12, 14, 16],
... [ 4, 36, 29, 13, 18, 11]])
True
''' '''
if (n < 3): if (n < 3):
raise ValueError('n must be greater than 2.') raise ValueError('n must be greater than 2.')

@ -7,7 +7,7 @@ import scipy.sparse as sparse
from numpy import ones, zeros, prod, sin, diff, pi, inf, vstack, linspace from numpy import ones, zeros, prod, sin, diff, pi, inf, vstack, linspace
from scipy.interpolate import PiecewisePolynomial, interp1d from scipy.interpolate import PiecewisePolynomial, interp1d
from . import polynomial as pl from wafo import polynomial as pl
__all__ = [ __all__ = [
@ -1015,7 +1015,8 @@ class StinemanInterp2(PiecewisePolynomial):
def __init__(self, x, y, yp=None, method='parabola', monotone=False): def __init__(self, x, y, yp=None, method='parabola', monotone=False):
if yp is None: if yp is None:
yp = slopes(x, y, method, monotone=monotone) yp = slopes(x, y, method, monotone=monotone)
super(StinemanInterp2, self).__init__(x, zip(y, yp)) yyp = [z for z in zip(y, yp)]
super(StinemanInterp2, self).__init__(x, yyp)
class CubicHermiteSpline(PiecewisePolynomial): class CubicHermiteSpline(PiecewisePolynomial):
@ -1028,7 +1029,8 @@ class CubicHermiteSpline(PiecewisePolynomial):
def __init__(self, x, y, yp=None, method='Catmull-Rom'): def __init__(self, x, y, yp=None, method='Catmull-Rom'):
if yp is None: if yp is None:
yp = slopes(x, y, method, monotone=False) yp = slopes(x, y, method, monotone=False)
super(CubicHermiteSpline, self).__init__(x, zip(y, yp), orders=3) yyp = [z for z in zip(y, yp)]
super(CubicHermiteSpline, self).__init__(x, yyp, orders=3)
class Pchip(PiecewisePolynomial): class Pchip(PiecewisePolynomial):
@ -1127,7 +1129,8 @@ class Pchip(PiecewisePolynomial):
def __init__(self, x, y, yp=None, method='secant'): def __init__(self, x, y, yp=None, method='secant'):
if yp is None: if yp is None:
yp = slopes(x, y, method=method, monotone=True) yp = slopes(x, y, method=method, monotone=True)
super(Pchip, self).__init__(x, zip(y, yp), orders=3) yyp = [z for z in zip(y, yp)]
super(Pchip, self).__init__(x, yyp, orders=3)
def interp3(x, y, z, v, xi, yi, zi, method='cubic'): def interp3(x, y, z, v, xi, yi, zi, method='cubic'):

@ -2819,7 +2819,7 @@ def _compute_qth_weighted_percentile(a, q, axis, out, method, weights,
if axis is None: if axis is None:
sorted_ = a.ravel() sorted_ = a.ravel()
else: else:
taxes = range(a.ndim) taxes = [i for i in range(a.ndim)]
taxes[-1], taxes[axis] = taxes[axis], taxes[-1] taxes[-1], taxes[axis] = taxes[axis], taxes[-1]
sorted_ = np.transpose(a, taxes).reshape(-1, shape0[axis]) sorted_ = np.transpose(a, taxes).reshape(-1, shape0[axis])

@ -584,8 +584,8 @@ def sub_dict_select(somedict, somekeys):
>>> kwds = dict(arg2=100,arg3=1000) >>> kwds = dict(arg2=100,arg3=1000)
>>> sub_dict = sub_dict_select(kwds,opt.keys()) >>> sub_dict = sub_dict_select(kwds,opt.keys())
>>> opt.update(sub_dict) >>> opt.update(sub_dict)
>>> opt >>> opt == {'arg1': 2, 'arg2': 100}
{'arg1': 2, 'arg2': 100} True
See also See also
-------- --------

@ -1595,13 +1595,13 @@ class TimeSeries(PlotData):
>>> for i in range(-3,4): >>> for i in range(-3,4):
... S, H = ts.wave_height_steepness(method=i) ... S, H = ts.wave_height_steepness(method=i)
... print(S[:2],H[:2]) ... print(S[:2],H[:2])
(array([ 0.01186982, 0.04852534]), array([ 0.69, 0.86])) [ 0.01186982 0.04852534]), [ 0.69, 0.86]
(array([ 0.02918363, 0.06385979]), array([ 0.69, 0.86])) [ 0.02918363, 0.06385979]) [ 0.69, 0.86]
(array([ 0.27797411, 0.33585743]), array([ 0.69, 0.86])) [ 0.27797411, 0.33585743]) [ 0.69, 0.86]
(array([ 0.60835634, 0.60930197]), array([ 0.42, 0.78])) [ 0.60835634, 0.60930197]) [ 0.42, 0.78]
(array([ 0.60835634, 0.60930197]), array([ 0.42, 0.78])) [ 0.60835634, 0.60930197]) [ 0.42, 0.78]
(array([ 0.10140867, 0.06141156]), array([ 0.42, 0.78])) [ 0.10140867, 0.06141156]) [ 0.42, 0.78]
(array([ 0.01821413, 0.01236672]), array([ 0.42, 0.78])) [ 0.01821413, 0.01236672]) [ 0.42, 0.78]
import pylab as plt import pylab as plt
h = plt.plot(S,H,'.') h = plt.plot(S,H,'.')

@ -6,8 +6,8 @@ from numpy import (pi, abs, size, convolve, linalg, concatenate, sqrt)
from scipy.sparse import spdiags from scipy.sparse import spdiags
from scipy.sparse.linalg import spsolve, expm from scipy.sparse.linalg import spsolve, expm
from scipy.signal import medfilt from scipy.signal import medfilt
from wafo.dctpack import dctn, idctn from .dctpack import dctn, idctn
from wafo.plotbackend import plotbackend as plt from .plotbackend import plotbackend as plt
import scipy.optimize as optimize import scipy.optimize as optimize
from scipy.signal import _savitzky_golay from scipy.signal import _savitzky_golay
from scipy.ndimage import convolve1d from scipy.ndimage import convolve1d

Loading…
Cancel
Save