Statistics
| Branch: | Revision:

mobicen / timeAnalysis.py @ fa4a0a42

History | View | Annotate | Download (1.39 KB)

1 fa4a0a42 LoreBz
import pandas as pd
2
from pprint import pprint
3
import numpy as np
4
import glob
5
from matplotlib import pyplot
6
from statsmodels.graphics.tsaplots import plot_acf, acf
7
import sys
8
import os
9
from collections import defaultdict
10
import matplotlib.pyplot as plt
11
import code  # code.interact(local=dict(globals(), **locals()))
12
13
folder = sys.argv[1]
14
lags = int(sys.argv[2])
15
os.chdir(folder)
16
17
timeBC = defaultdict(list)
18
print "Loading data from", folder, "..."
19
for snap in sorted(glob.glob('./BC*')):
20
    # print snap
21
    df = pd.read_csv(snap, names=['Node', 'BC'], skiprows=1)
22
    for index, row in df.iterrows():
23
        timeBC[int(row.Node)].append(row.BC)
24
25
print "Processing data..."
26
lags2NodeACF = defaultdict(list)
27
for node in timeBC:
28
    nodeACF = acf(timeBC[node], nlags=lags)
29
    for lag in range(0, len(nodeACF)):
30
        lags2NodeACF[lag].append(nodeACF[lag])
31
32
#code.interact(local=dict(globals(), **locals()))
33
34
os.chdir("./..")
35
# Plotting
36
37
#lags=20
38
x = range(0, lags)
39
y = []
40
for i in x:
41
    y.append(np.mean(lags2NodeACF[i]))
42
43
#plt.plot(x, y, marker=".", lw="1.5")
44
#plt.stem(x, y, markerfmt=' ')
45
46
plt.stem(x, y, s=0.1)
47
plt.ylabel('Mean Autocorrelation')
48
plt.xlabel('Time-lags')
49
#plt.ylim(-1.0,1.0)
50
plt.xlim(0,lags)
51
52
#plt.title("Mean Autocorrelation X time-lag", y=1.04)
53
plt.savefig("autoCorrMean.pdf", format='pdf')
54
plt.clf()
55
print "Plot saved in", folder+".."
56
print "THE END"
57
#plot_acf(timeBC[0.0], lags=lags)
58
#pyplot.show()