-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathiotxt.py
128 lines (89 loc) · 4.13 KB
/
iotxt.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
import csv
import json
import numpy
import pickle
paths = {
'datasets': "$HOME/Thesis/datasets",
'harmonic_change_temp': "./out/harmonic_change/",
'eval_temp': "./out/eval/",
'chroma_temp': "./out/chroma/",
'tonal_model_temp': "./out/tonal_model/",
'gaussian_blur_temp': "./out/gaussian_blur/",
'blur_temp': "./out/blur/",
'audio_temp': "./out/audio/",
'node_in': "in/node1.json"
}
def save_centroids(centroids, name_file):
with open('out/' + name_file + '_centroids.csv', 'w') as f:
f.write("c[0],c[1],c[2],c[3],c[4],c[5]\n")
for j in range(0, centroids.shape[1]):
for i in range(0, centroids.shape[0]):
f.write("%s," % centroids[i][j])
f.write("\n")
def save_hcdf(vector, changes, name_file):
with open('out/' + name_file + '_hcdf.csv', 'w') as f:
f.write("euclidian distance,\n")
for s in vector:
f.write("%s\n" % s)
def save_changes(changes, name_file):
with open('out/' + name_file + '_changes.csv', 'w') as f:
f.write("from time,to time,c[0],c[1],c[2],c[3],c[4],c[5]\n")
for i in range(0, changes.shape[0]):
for j in range(0, changes.shape[1]):
f.write("%s," % changes[i][j])
f.write("\n")
def save_results(centroid_vector, harmonic_function, changes, name_file):
save_centroids(centroid_vector, name_file)
save_hcdf(harmonic_function, changes, name_file)
save_changes(changes, name_file)
def load_real_onset(filename, dataset="/Queen/"):
real_chords = []
delimeter = ' ' if dataset == '/The Beatles/' else '\t'
with open(filename) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=delimeter)
for row in csv_reader:
real_chords.append(float(row[0]))
return numpy.array(real_chords)
def load_real_chords(filename, dataset="/Queen/"):
real_chords = []
delimeter = ' ' if dataset == '/The Beatles/' else '\t'
with open(filename) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=delimeter)
for row in csv_reader:
real_chords.append(str(row[0]) + "-" + str(row[2]))
return numpy.array(real_chords)
# Functions for save informations in hcdf
def save_json(dictionary, name_file):
with open(name_file, 'w') as fp:
json.dump(dictionary, fp, sort_keys=True, indent=4)
def load_json(name_file):
data = None
with open(name_file, 'r') as fp:
data = json.load(fp)
return data
def save_binary(dictionary, name_file):
with open(name_file, 'wb') as fp:
pickle.dump(dictionary, fp, protocol=pickle.HIGHEST_PROTOCOL)
def load_binary(name_file):
data = None
with open(name_file, 'rb') as fp:
data = pickle.load(fp)
return data
def get_name_audio(name_file, hpss, sr, codec='.pickle'):
hpss_name = 'hpss' if hpss else 'none'
return paths["audio_temp"] + "audio." + name_file + '.' + hpss_name + '.' + str(sr) + codec
def get_name_chromagram(name_file, hpss, chroma, codec='.pickle'):
hpss_name = 'hpss' if hpss else 'none'
return paths["chroma_temp"] + "chroma." + name_file + '.' + hpss_name + '.' + chroma + codec
def get_name_tonal_model(name_file, hpss, chroma, tonal_model, codec='.pickle'):
hpss_name = 'hpss' if hpss else 'none'
return paths["tonal_model_temp"] + "tonal." + name_file + '.' + hpss_name + '.' + chroma + '.' + tonal_model + codec
def get_name_gaussian_blur(name_file, hpss, chroma, tonal_model, blur, sigma, log_compresion, codec='.pickle'):
hpss_name = 'hpss' if hpss else 'none'
return paths["gaussian_blur_temp"] + "blur." + name_file + '.' + hpss_name + '.' + chroma + '.' + tonal_model + '.' + blur + '.' + 'sigma' + str(sigma) + '.' + log_compresion + codec
def get_name_eval(filename, hpss, tonal_model, chroma, blur, sigma, log_compresion, distance, codec='.json'):
hpss_name = 'hpss' if hpss else 'none'
return paths["eval_temp"] + "eval." + filename + '.' + hpss_name + '.' + chroma + '.' + tonal_model + '.' + blur+ '.' + 'sigma' + str(sigma) + '.' + log_compresion + '.' + distance + codec
def get_name_harmonic_change(filename, hpss, tonal_model, chroma, blur, sigma, log_compresion, distance, codec='.pickle'):
hpss_name = 'hpss' if hpss else 'none'
return paths["harmonic_change_temp"] + "hcdf." + filename + '.' + hpss_name + '.' + chroma + '.' + tonal_model + '.' + blur + '.' + 'sigma' + str(sigma) + '.' + log_compresion + '.' + distance + codec