-
Notifications
You must be signed in to change notification settings - Fork 0
/
recopilar_data.py
executable file
·61 lines (48 loc) · 1.35 KB
/
recopilar_data.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
#!/usr/bin/env python3
import os
from statistics import mean, stdev
def traverse_folders(data, names, level=0):
if level >= len(names):
write_aggregate(data)
return
else:
name = names[level]
for dirname in os.listdir():
if os.path.isdir(dirname) and dirname.endswith(f'_{name}'):
data_new = data + [dirname.split('_')[0]]
os.chdir(dirname)
traverse_folders(data_new, names, level+1)
os.chdir('..')
def write_aggregate(data):
with open('output.dat', 'r') as file:
next(file) # skip headers
zipped = zip(*(map(float, line.split()[1:]) for line in file.readlines()))
aggregated = [
str(x)
for values in zipped
for x in (mean(values), mean(map(lambda x: x**2, values)))
]
data = '\t'.join(data+aggregated)+'\n'
datafile.write(data)
HEADER = '\t'.join((
'densidad',
'temperatura',
'job',
'potencial_mean',
'potencial_2',
'cinetica_mean',
'cinetica_2',
'total_mean',
'total_2',
'presion_mean',
'presion_2',
))+'\n'
OUTFILE = 'alldata.dat'
DATAFOLDER = 'data'
NAMES = ['dens', 'temp', 'JOB']
with open(OUTFILE, 'w') as datafile:
datafile.write(HEADER)
data = []
os.chdir(DATAFOLDER)
traverse_folders(data, NAMES)
os.chdir('..')