def _get_relative_note_occurences(note_models, pitch_distribution):
max_rel_occur = 0
for note_symbol, note in iteritems(note_models):
try:
# get the relative occurrence of each note from the pitch
# distribution
dists = np.array([abs(note['stable_pitch']['value'] - dist_bin)
for dist_bin in pitch_distribution.bins])
except TypeError:
logging.info(u'The stable pitch for {0:s} is not computed'
.format(note_symbol))
# use the max peak even if it's weak, far from theoretical etc.
peak_idx, heights = note['distribution'].detect_peaks()
max_peak_ind = peak_idx[np.argmax(heights)]
max_bin = note['distribution'].bins[max_peak_ind]
dists = np.array([abs(max_bin - dist_bin)
for dist_bin in pitch_distribution.bins])
peak_ind = np.argmin(dists)
note['rel_occur'] = pitch_distribution.vals[peak_ind]
max_rel_occur = max([max_rel_occur, note['rel_occur']])
return max_rel_occur
评论列表
文章目录