Exemple #1
0
def test_smoothn_1d():
    x = np.linspace(0, 100, 2 ** 8)
    y = np.cos(x / 10) + (x / 50) ** 2 + np.random.randn(x.size) / 10
    y[np.r_[70, 75, 80]] = np.array([5.5, 5, 6])
    z = smoothn(y)  # Regular smoothing
    zr = smoothn(y, robust=True)  # Robust smoothing
    plt.subplot(121),
    unused_h = plt.plot(x, y, 'r.', x, z, 'k', linewidth=2)
    plt.title('Regular smoothing')
    plt.subplot(122)
    plt.plot(x, y, 'r.', x, zr, 'k', linewidth=2)
    plt.title('Robust smoothing')
    plt.show('hold')
Exemple #2
0
def demo_smoothn_on_1d_cos():
    """
    Examples
    --------
    >>> demo_smoothn_on_1d_cos()

    >>> plt.close()
    """
    x = np.linspace(0, 100, 2**8)
    y = np.cos(x / 10) + (x / 50)**2 + np.random.randn(np.size(x)) / 10
    y[np.r_[70, 75, 80]] = np.array([5.5, 5, 6])
    z = smoothn(y)  # Regular smoothing
    zr = smoothn(y, robust=True)  # Robust smoothing
    _h0 = plt.subplot(121),
    _h = plt.plot(x, y, 'r.', x, z, 'k', linewidth=2)
    plt.title('Regular smoothing')
    plt.subplot(122)
    plt.plot(x, y, 'r.', x, zr, 'k', linewidth=2)
    plt.title('Robust smoothing')
Exemple #3
0
def demo_smoothn_on_2d_exp_sin():
    """
    Examples
    --------
    >>> demo_smoothn_on_2d_exp_sin()

    >>> plt.close()
    """
    xp = np.arange(0, 1, 0.02)  # np.r_[0:1:0.02]
    [x, y] = np.meshgrid(xp, xp)
    f = np.exp(x + y) + np.sin((x - 2 * y) * 3)
    fn = f + np.random.randn(*f.shape) * 0.5
    _fs, s = smoothn(fn, fulloutput=True)
    fs2 = smoothn(fn, s=2 * s)
    _h = plt.subplot(131),
    _h = plt.contourf(xp, xp, fn)
    _h = plt.subplot(132),
    _h = plt.contourf(xp, xp, fs2)
    _h = plt.subplot(133),
    _h = plt.contourf(xp, xp, f)
Exemple #4
0
def test_smoothn_2d():

    # import mayavi.mlab as plt
    xp = np.r_[0:1:.02]
    [x, y] = np.meshgrid(xp, xp)
    f = np.exp(x + y) + np.sin((x - 2 * y) * 3)
    fn = f + np.random.randn(*f.shape) * 0.5
    fs, s = smoothn(fn, fulloutput=True)  # @UnusedVariable
    fs2 = smoothn(fn, s=2 * s)
    plt.subplot(131),
    plt.contourf(xp, xp, fn)
    plt.subplot(132),
    plt.contourf(xp, xp, fs2)
    plt.subplot(133),
    plt.contourf(xp, xp, f)
    plt.show('hold')
Exemple #5
0
    def plotfitsummary(self):
        ''' Plot various diagnostic plots to asses the quality of the fit.

        PLOTFITSUMMARY displays probability plot, density plot, residual
        quantile plot and residual probability plot.
        The purpose of these plots is to graphically assess whether the data
        could come from the fitted distribution. If so the empirical- CDF and
        PDF should follow the model and the residual plots will be linear.
        Other distribution types will introduce curvature in the residual
        plots.
        '''
        plotbackend.subplot(2, 2, 1)
        # self.plotecdf()
        self.plotesf()
        plotbackend.subplot(2, 2, 2)
        self.plotepdf()
        plotbackend.subplot(2, 2, 3)
        self.plotresq()
        plotbackend.subplot(2, 2, 4)
        self.plotresprb()

        fixstr = ''
        if self.par_fix is not None:
            numfix = len(self.i_fixed)
            if numfix > 0:
                format0 = ', '.join(['%d'] * numfix)
                format1 = ', '.join(['%g'] * numfix)
                phatistr = format0 % tuple(self.i_fixed)
                phatvstr = format1 % tuple(self.par[self.i_fixed])
                fixstr = 'Fixed: phat[%s] = %s ' % (phatistr, phatvstr)

        infostr = 'Fit method: %s, Fit p-value: %2.2f %s' % (
            self.method, self.pvalue, fixstr)
        try:
            plotbackend.figtext(0.05, 0.01, infostr)
        except:
            pass
Exemple #6
0
def demo_savitzky_on_noisy_chirp():
    """
    Examples
    --------
    >>> demo_savitzky_on_noisy_chirp()

    >>> plt.close()
    """
    plt.figure(figsize=(7, 12))

    # generate chirp signal
    tvec = np.arange(0, 6.28, .02)
    true_signal = np.sin(tvec * (2.0 + tvec))
    true_d_signal = (2 + tvec) * np.cos(tvec * (2.0 + tvec))

    # add noise to signal
    noise = np.random.normal(size=true_signal.shape)
    signal = true_signal + .15 * noise

    # plot signal
    plt.subplot(311)
    plt.plot(signal)
    plt.title('signal')

    # smooth and plot signal
    plt.subplot(312)
    savgol = SavitzkyGolay(n=8, degree=4)
    s_signal = savgol.smooth(signal)
    s2 = smoothn(signal, robust=True)
    plt.plot(s_signal)
    plt.plot(s2)
    plt.plot(true_signal, 'r--')
    plt.title('smoothed signal')

    # smooth derivative of signal and plot it
    plt.subplot(313)
    savgol1 = SavitzkyGolay(n=8, degree=1, diff_order=1)

    dt = tvec[1] - tvec[0]
    d_signal = savgol1.smooth(signal) / dt

    plt.plot(d_signal)
    plt.plot(true_d_signal, 'r--')
    plt.title('smoothed derivative of signal')
Exemple #7
0
#! Section 4.3.1 Crossing intensity
#!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import numpy as np
from wafo.plotbackend import plotbackend as plt
import wafo.data as wd
import wafo.objects as wo

xx_sea = wd.sea()
ts = wo.mat2timeseries(xx_sea)
tp = ts.turning_points()
mM = tp.cycle_pairs(kind='min2max')
lc = mM.level_crossings(intensity=True)
T_sea = ts.args[-1] - ts.args[0]

plt.subplot(1, 2, 1)
lc.plot()
plt.subplot(1, 2, 2)
lc.setplotter(plotmethod='step')
lc.plot()
plt.show()

m_sea = ts.data.mean()
f0_sea = np.interp(m_sea, lc.args, lc.data)
extr_sea = len(tp.data) / (2 * T_sea)
alfa_sea = f0_sea / extr_sea
print('alfa = %g ' % alfa_sea)

#! Section 4.3.2 Extraction of rainflow cycles
#!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#! Min-max and rainflow cycle plots
Exemple #8
0
#! Section 4.3.1 Crossing intensity
#!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import numpy as np
from wafo.plotbackend import plotbackend as plt
import wafo.data as wd
import wafo.objects as wo

xx_sea = wd.sea()
ts = wo.mat2timeseries(xx_sea)
tp = ts.turning_points()
mM = tp.cycle_pairs(kind='min2max')
lc = mM.level_crossings(intensity=True)
T_sea = ts.args[-1]-ts.args[0]

plt.subplot(1,2,1)
lc.plot()
plt.subplot(1,2,2)
lc.setplotter(plotmethod='step')
lc.plot()
plt.show()


m_sea = ts.data.mean()
f0_sea = np.interp(m_sea, lc.args,lc.data)
extr_sea = len(tp.data)/(2*T_sea)
alfa_sea = f0_sea/extr_sea
print('alfa = %g ' % alfa_sea)

#! Section 4.3.2 Extraction of rainflow cycles
#!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Exemple #9
0
#hold on
#tp = dat2tp(xs);
#rfc = tp2rfc(tp);
#plot(rfc(:, 2), rfc(:, 1), '.')
#wafostamp('', '(ER)')
#hold off
#disp('Block = 9'), pause(pstate)

#! Section 1.4.5 Extreme value statistics
#!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Plot of yura87 data
plt.clf()
import wafo.data as wd
xn = wd.yura87()
#xn = load('yura87.dat');
plt.subplot(211)
plt.plot(xn[::30, 0] / 3600, xn[::30, 1], '.')
plt.title('Water level')
plt.ylabel('(m)')

#! Formation of 5 min maxima
yura = xn[:85500, 1]
yura = np.reshape(yura, (285, 300)).T
maxyura = yura.max(axis=0)
plt.subplot(212)
plt.plot(xn[299:85500:300, 0] / 3600, maxyura, '.')
plt.xlabel('Time (h)')
plt.ylabel('(m)')
plt.title('Maximum 5 min water level')
plt.show()
Exemple #10
0
#hold on
#tp = dat2tp(xs);
#rfc = tp2rfc(tp);
#plot(rfc(:, 2), rfc(:, 1), '.')
#wafostamp('', '(ER)')
#hold off
#disp('Block = 9'), pause(pstate)

#! Section 1.4.5 Extreme value statistics
#!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Plot of yura87 data
plt.clf()
import wafo.data as wd
xn = wd.yura87()
#xn = load('yura87.dat');
plt.subplot(211)
plt.plot(xn[::30, 0] / 3600, xn[::30, 1], '.')
plt.title('Water level')
plt.ylabel('(m)')

#! Formation of 5 min maxima
yura = xn[:85500, 1]
yura = np.reshape(yura, (285, 300)).T
maxyura = yura.max(axis=0)
plt.subplot(212)
plt.plot(xn[299:85500:300, 0] / 3600, maxyura, '.')
plt.xlabel('Time (h)')
plt.ylabel('(m)')
plt.title('Maximum 5 min water level')
plt.show()