Esempio n. 1
0
 def calc_time_series(self):
     data = zeros(self.Nbins, 'f')
     data.savespace()
     # Place the non-pulsed photons
     points = randint(0, self.Nbins, self.backgdphot)
     for point in points:
         data[point] = data[point] + 1.0
     # Place the pulsed photons
     pulses = randint(0, self.freq, self.pulsedphot)
     if pulsetype == 'Sine':
         x = arange(10001, typecode='d') * TWOPI / 10000
         coscdf = (x + sin(x)) / TWOPI
         uvar = random(self.pulsedphot)
         phases = take((x + TWOPI * random()) % TWOPI,
                       searchsorted(coscdf, uvar)) / TWOPI
         # plotxy(coscdf, x)
         # closeplot()
         # hist = histogram(phases, 100, [0.0, TWOPI])
         # plotbinned(hist[:,1], hist[:,0])
         # closeplot()
     elif pulsetype == 'Gaussian':
         phases = normal(0.0, width, self.pulsedphot) % 1.0 + random()
     points = ((pulses + phases) / self.freq * self.Nbins).astype('i')
     for point in points:
         data[point] = data[point] + 1.0
         # tmp = average(data)
         # print 'Average Data = ', tmp
         # print '   sqrt(avg) = ', sqrt(tmp)
         # print ' StdDev Data = ', standardDeviation(data)
     return data
Esempio n. 2
0
 def calc_time_series(self):
     data = zeros(self.Nbins, 'f')
     data.savespace()
     # Place the non-pulsed photons
     points = randint(0, self.Nbins, self.backgdphot)
     for point in points:
         data[point] = data[point] + 1.0
     # Place the pulsed photons
     pulses = randint(0, self.freq, self.pulsedphot)
     if pulsetype=='Sine':
         x = arange(10001, typecode='d') * TWOPI/10000
         coscdf = (x + sin(x))/TWOPI
         uvar = random(self.pulsedphot)
         phases = take((x + TWOPI * random()) % TWOPI,
                       searchsorted(coscdf, uvar)) / TWOPI
         # plotxy(coscdf, x)
         # closeplot()
         # hist = histogram(phases, 100, [0.0, TWOPI])
         # plotbinned(hist[:,1], hist[:,0])
         # closeplot()
     elif pulsetype=='Gaussian':
         phases = normal(0.0, width, self.pulsedphot) % 1.0 + random()
     points = ((pulses + phases) / self.freq * self.Nbins).astype('i')
     for point in points:
         data[point] = data[point] + 1.0
         # tmp = average(data)
         # print 'Average Data = ', tmp
         # print '   sqrt(avg) = ', sqrt(tmp)
         # print ' StdDev Data = ', standardDeviation(data)
     return data
Esempio n. 3
0
from __future__ import division
from scipy import signal, arange, sin, pi
from RandomArray import normal
from scipy.signal import buttord, butter, lfilter
import Interactive

dt = 0.001
t = arange(0.0, 10.0, dt)
nse = normal(0, 1.4, t.shape)
#s = sin(2*pi*t) + nse
s = nse

lpcf = 3
lpsf = 5
Nyq = 1 / (2 * dt)
Rp = 1
Rs = 500
Wp = lpcf / Nyq
Ws = lpsf / Nyq
d = 0.5
e = 0.0000000001
[n, Wn] = buttord([d - e, d], [d - e - e, d + e], Rp, Rs)
[b, a] = butter(n, Wn)
xlp = lfilter(b, a, s)

Interactive.show(xlp)
Esempio n. 4
0
parsTrue = array([2.0, -.76, 0.1])
distance = linspace(0, 4, 1000)


def func(pars):
    a, alpha, k = pars
    return a * exp(alpha * distance) + k


def errfunc(pars):
    return data - func(pars)  #return the error


# some pseudo data; add some noise
data = func(parsTrue) + normal(0.0, 0.1, distance.shape)

# the intial guess of the params
guess = 1.0, -.4, 0.0

# now solve for the best fit paramters
best, info, ier, mesg = leastsq(errfunc, guess, full_output=1)

print 'true', parsTrue
print 'best', best
print '|err|_l2 =', P.l2norm(parsTrue - best)

# scipy's splrep uses FITPACK's curfit (B-spline interpolation)
print 'Spline smoothing of the data'
sp = splrep(distance, data)
smooth = splev(distance, sp)
from scipy.interpolate import splrep,splev

import pylab as P

parsTrue = array([2.0, -.76, 0.1])
distance = linspace(0, 4, 1000)

def func(pars):
    a, alpha, k = pars
    return a*exp(alpha*distance) + k

def errfunc(pars):
    return data - func(pars)  #return the error

# some pseudo data; add some noise
data = func(parsTrue) + normal(0.0, 0.1, distance.shape)

# the intial guess of the params
guess = 1.0, -.4, 0.0

# now solve for the best fit paramters
best, info, ier, mesg = leastsq(errfunc, guess, full_output=1)

print 'true', parsTrue
print 'best', best
print '|err|_l2 =',P.l2norm(parsTrue-best)

# scipy's splrep uses FITPACK's curfit (B-spline interpolation)
print 'Spline smoothing of the data'
sp = splrep(distance,data)
smooth = splev(distance,sp)
Esempio n. 6
0
from matplotlib.matlab import *
from RandomArray import normal
from Numeric import sin, exp, multiply, absolute, pi


def f(t):
    s1 = sin(2 * pi * t)
    e1 = exp(-t)
    return absolute(multiply(s1, e1)) + .05


t = arange(0.0, 5.0, 0.1)
s = f(t)
nse = multiply(normal(0.0, 0.3, t.shape), s)

plot(t, s + nse, 'b^')
vlines(t, 0, s, color='k')
xlabel('time (s)')
title('Comparison of model with data')
show()
Esempio n. 7
0
from matplotlib.matlab import *
from RandomArray import normal
from Numeric import sin, exp, multiply, absolute, pi

def f(t):
    s1 = sin(2*pi*t)
    e1 = exp(-t)
    return absolute(multiply(s1,e1))+.05


t = arange(0.0, 5.0, 0.1)
s = f(t)
nse = multiply(normal(0.0, 0.3, t.shape), s)

plot(t, s+nse, 'b^')
vlines(t, 0, s, color='k')
xlabel('time (s)')
title('Comparison of model with data')
show()