-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReccNetHeterogeinity.py
More file actions
130 lines (110 loc) · 3.05 KB
/
ReccNetHeterogeinity.py
File metadata and controls
130 lines (110 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#This version finds the degree distribution and heretogeinity of time series
import numpy as np
import math
import sys
import time as tm
import subprocess as sbp
import graph_tool as gt
import graph_tool.clustering as gcl
import graph_tool.topology as gtop
from numpy import conjugate,absolute
import matplotlib.pyplot as plt
import readline, glob
import os
def complete(text, state):
return (glob.glob(text+'*')+[None])[state]
readline.set_completer_delims(' \t\n;')
readline.parse_and_bind("tab: complete")
readline.set_completer(complete)
def embedder(fn,ch):
#function to embed an attractor using mutual information or autocorrelation
opt='a'
t1=[]
tau=1
temp1=0
temp2=0
temp3=0
if(ch=='c'):
fn="Com_"+fn
else:
fn=fn
fin=open(fn,"r")
if (opt=='a'):
os.system ("./corr "+fn+" -o temper -D 200")
fin1=open("temper","r")
t1=fin1.readlines()
for i in range (2,len(t1)-2):
temp1=t1[i].split()
if(float(temp1[1])<0.36787944117):
tau=temp1[0]
break
fin1.close()
print tau
fin=open(fn,"r")
a=fin.readlines()
a=a[0:NN]
for i in range (0,len(a)):
a[i]=a[i].strip()
fout=open("em_"+fn,"w")
tau=int(tau)
dim=4
em_at=np.zeros((len(a)-((dim-1)*tau),dim))
for i in range(0,len(a)-((dim-1)*tau)):
for j in range (0,dim):
em_at[i][j]=a[i+(j*tau)]
np.savetxt("em_"+fn,em_at, delimiter='\t')
#Move it into a new folder
return em_at
#Done till this point
fout_sig=open("Het_SD_CleanedStars.dat","w")
file_list=glob.glob("ud_*.dat")
print "Number of files:",len(file_list)
for fn in file_list:
b=np.loadtxt(fn)
l1=len(b)
print fn
print "Length of file is",len(b)
temp_fil=fn.split("_")
if(len(b)<3000):
leng=len(b)-1
NN=len(b)-1
else:
leng=3000
NN=3000
#leng=int(float(temp_fil[2][2:6])*float(temp_fil[3][2:4]))
#leng=input(". Enter length to truncate to. ")
a=b[0:leng]
ts=.0204#input("Sampling period")
print "Length of dataset is", len(a), ". Please ensure this is a power of 2."
loc_time=tm.strftime("%Y-%m-%d")
fa=[]
fs=1.0/ts
print "Maximum frequency is", fs
#ns=int(temp_fil[3][2:4])#input("Number of segments")
#Reduces the average from the whole time series
file_mean=np.mean(a)
print file_mean
for i in range (0,leng):
a[i]=a[i]-file_mean
epsilon=.14
#fn1="ud_"+fn
udc="u" #This option is brought forward from a previous version that had an option to not have uniform deviates
#if(udc=="u")or(udc=="U"):
# os.system ("./UD.out "+fn+" "+str(NN))
# fn1="ud_"+fn
em_at1=embedder(fn,udc)
#if(udc=="u")or(udc=="U"):
os.system ("./ELDD.out em_"+fn+" "+str(NN)+" "+str(epsilon))
print "./ELDD.out em_"+fn+" "+str(NN)+" "+str(epsilon)
p1=sbp.Popen('./Het.out',stdin=sbp.PIPE,shell=True)
p1.communicate("dd_em_"+fn)
sys.stdout.flush()
sys.stdin.flush()
finhet=open("Het_Measuredd_em_"+fn)
a1=finhet.readlines()
temphet=a1[2].split()
het=temphet[2]
fout_sig.write(str(temp_fil[1][4:len(temp_fil[1])])+'\t'+str(het)+'\n')
print str(temp_fil[1][4:len(temp_fil[1])])+'\t'+str(het)+'\n'
os.rename("dd_em_"+fn,"./Het/dd_em_"+fn)
os.rename("Het_Measuredd_em_"+fn,"./Het/Het_Measuredd_em_"+fn)