Generate Fake Trace

Import random library


In [1]:
import random

Seed the random number generator.


In [2]:
random.seed()

Generate list of exponentially distributed numbers, which will comprise the distribution of dwell durations.


In [3]:
dwell = []
meanDur = 24
numDwells = 50

dwell = []
for d in range(numDwells):
    dwell.append(int(round(random.expovariate(1.0/meanDur))))

dwell[0:5]


Out[3]:
[25, 2, 35, 8, 14]

Generate a fake trace using the distribution of dwells with Gaussian distributed noise


In [4]:
start = 5
sigma = 2
stepSize = 2

trace = []
fit = []
for d in range(len(dwell)): # iterate through all dwells
    for p in range(dwell[d]): # iterate through each point in current dwell
        trace.append(random.gauss(start,sigma))
        fit.append(start)
    start += stepSize
print(trace[0:5])


[5.047189551350871, 6.57551429872053, 0.8766445000128815, 5.243107431580079, 8.429068759452168]

Histogram dwell durations, confirm single exponential behavior


In [5]:
hist(dwell,bins=10, histtype='step');
title("histogram of dwell durations")
xlabel('dwell duration');
ylabel('counts');



In [6]:
plot(trace);
plot(fit,'r',lw=2);
title("example fake trace");
xlabel("time"); #xlim(1000,1125)
ylabel("signal"); #ylim(55,62.5)


Out[6]:
<matplotlib.text.Text at 0x7fe63082c090>

Export the data


In [10]:
data=[]
data=[[i,trace[i]/20,trace[i]] for i in range(len(trace))]
np.savetxt('./stationary_trace_3.txt', data, delimiter = ' ')

data=[]
data=[[i,fit[i]] for i in range(len(trace))]
np.savetxt('./stationary_fit_3.txt', data, delimiter = ' ')

In [22]: