-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_data.py
115 lines (87 loc) · 3.46 KB
/
get_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
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
import numpy as np
import ast
import itertools
import re
import os
from os.path import exists
import pandas as pd
from datetime import datetime,timezone
import pytz
def padd_to_n(main_list,n):
return [lst + [0.0] * (n - len(lst)) for lst in main_list]
def fill_zeros(input_list, N): #depricated
return input_list + [0.0] * (int(N) - len(input_list))
def pad_list_with_zeros(lists):
max_len = max(len(lst) for lst in lists)
return [lst + [0.0] * (max_len - len(lst)) for lst in lists]
def read_data_AXB_n(path,n):
aux=[]
with open(path+'/AXB.txt','r') as file:
head= [next(file) for x in range(n)]
for line in head:
if line == '\n': break
# list=re.findall("(?<=[AZaz])?(?!\d*=)[0-9.+-]+",line) #old regex. Error with letter e
list=re.findall("(?<=[AZaz])?(?!\d*=)[eE0-9.+-]+", line)
list= [round(float(i),7) for i in list]
aux.append(list)
return aux
def read_data_P_n(path,n):
aux=[]
with open(path+'/DS_P.txt','r') as file:
head= [next(file) for x in range(n)]
for line in head:
# if line == '\n': break
list=re.findall("(?<=[AZaz])?(?!\d*=)[eE0-9.+-]+", line)
list= [round(float(i),7) for i in list]
aux.append(list)
return aux
def read_data_width_n(path,n):
aux=[]
with open(path+'/intervals_change.txt','r') as file:
head= [next(file) for x in range(n)]
for line in head:
# if line == '\n': break
list = line.split()
list= [round(float(i),7) for i in list]
aux.append(list)
return aux
def read_data_AXB_variation(path,start,end):
aux=[]
with open(path+'/AXB.txt','r') as file:
for line_number, line in enumerate(file):
if start-1<=line_number and line_number<=end-1:
list=re.findall("(?<=[AZaz])?(?!\d*=)[eE0-9.+-]+", line)
list=[round(float(i),7) for i in list]
aux.append(list)
return aux
def read_data_width_n_variation(path,start,end):
aux=[]
with open(path+'/intervals_change.txt','r') as file:
for line_number, line in enumerate(file):
if start-1<=line_number and line_number<=end-1:
list=line.split()
list=[round(float(i),7) for i in list]
aux.append(list)
return aux
def read_data_P_variation(path,start,end):
aux=[]
with open(path+'/DS_P.txt','r') as file:
for line_number, line in enumerate(file):
if start-1<=line_number and line_number<=end-1:
list=re.findall("(?<=[AZaz])?(?!\d*=)[eE0-9.+-]+", line)
list=[round(float(i),7) for i in list]
aux.append(list)
return aux
def make_json_history(folder,data): #deprecated
hist_df = pd.DataFrame(data)
hist_json_file =folder+'/history.json'
with open(hist_json_file, mode='w') as f:
hist_df.to_json(f)
def save_model_summary(folder,config,model):
with open(folder+'/config.txt','w') as fh:
for key, value in config.items():
fh.write('%s: %s\n' % (key, value))
model.summary(print_fn=lambda x: fh.write(x + '\n'))
def save_all(folder,config,acti_funs,model,data): #deprecated
make_json_history(folder,data)
save_model_summary(folder,config,acti_funs,model)