-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert_data_for_matrix_plotting.py
130 lines (74 loc) · 2.9 KB
/
convert_data_for_matrix_plotting.py
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
#!/usr/bin/env python
'''
Code to read the pickle file with the raw data from the DAU experiments,
and make it into a csv file.
Created by Julia Poncela, on December 2014.
'''
import pickle
from unidecode import unidecode # to transform whatever unicode special characters into just plain ascii (otherwise networkx complains)
import histograma_bines_gral
import numpy
from scipy import stats
def main():
reverse_flag=0 # depending on the ordering of the data, it inverts the representation... (try and error)
# name0="../Results/ST_replicator_simus.dat" # ojo!!! en este archivo esta primero la S y luego la T!!!!!!!!!!
# name0="../Results/Ratio_Cooperation_TSplane_genders.dat"
#name0="../Results/Ratio_Cooperation_TSplane_rounds_4_10_div_11_18.dat"
name0="../Results/Diff_relat_Cooperation_TSplane_rounds_4_10_div_11_18.dat"
file0=open(name0,'r')
list_lines=file0.readlines()
dict_TSplane_avg_coop={}
for line in list_lines:
print line
try:
list_elements=line.strip("\n").split(" ")
if name0=="../Results/ST_replicator_simus.dat":
T=int(list_elements[1])# ojo!!! en este archivo esta primero la S y luego la T!!!!!
S=int(list_elements[0])
else:
T=int(list_elements[0])
S=int(list_elements[1])
avg_coop=float(list_elements[2])
punto_TS=(T,S)
dict_TSplane_avg_coop[punto_TS]=avg_coop
except:
pass
print_values_dict_for_matrix_plotting(dict_TSplane_avg_coop, name0,reverse_flag)
######################################
######################################
def print_values_dict_for_matrix_plotting(dict_TSplane_avg_values, filename, reverse_flag):
filename=filename.split(".dat")[0]+"_MATRIX.dat"
output= open(filename,'wt')
list_T_values=[]
list_S_values=[]
for key in dict_TSplane_avg_values:
T=key[0]
S=key[1]
if T not in list_T_values:
list_T_values.append(T)
if S not in list_S_values:
list_S_values.append(S)
listT=sorted(list_T_values)
listS=sorted(list_S_values)
if reverse_flag== 1:
listT.reverse()
listS.reverse()
for T in listT:
for S in listS:
tupla=(T,S)
try:
print >> output, dict_TSplane_avg_values[tupla],
except KeyError:
pass
print >> output
output.close()
print "written matrix file:", filename
######################################
######################################
######################################
if __name__ == '__main__':
# if len(sys.argv) > 1:
# graph_filename = sys.argv[1]
main()
#else:
# print "Usage: python script.py "