def plot_simmat(simmat, labfile=''): """ Plot a similarity matrix """ # postprocess simmat simmat2 = copy.deepcopy(simmat) if False: allvals = np.sort(simmat2.flatten()) medianval = allvals[int(allvals.shape[0] / 2)] simmat2[np.where(simmat2 > medianval)] = medianval # plot import pylab as P P.figure() args2 = {'interpolation': 'nearest', 'cmap': P.cm.gray, 'aspect': 'auto'} P.imshow(simmat2, **args2) P.colorbar() P.hold(True) # we have labfile? if labfile != '': startbeats, stopbeats, labels = DUMMY.read_lab_file(labfile) for sb in startbeats: pos = sb assert pos <= simmat.shape[1], 'wrong pos for lab data' point_size = 30 P.scatter(pos, pos, s=point_size, c='r', marker='o') P.scatter(pos, 0, s=point_size, c='r', marker='o') P.scatter(0, pos, s=point_size, c='r', marker='o') P.hold(False) # diff simmat_diff = np.diff(simmat2) P.figure() args2 = {'interpolation': 'nearest', 'cmap': P.cm.gray, 'aspect': 'auto'} P.imshow(simmat_diff, **args2) P.colorbar() P.hold(True) # we have labfile? if labfile != '': startbeats, stopbeats, labels = DUMMY.read_lab_file(labfile) for sb in startbeats: pos = sb - 1 assert pos <= simmat.shape[1], 'wrong pos for lab data' point_size = 30 P.scatter(pos, pos, s=point_size, c='r', marker='o') P.scatter(pos, 0, s=point_size, c='r', marker='o') P.scatter(0, pos, s=point_size, c='r', marker='o') P.hold(False) # show P.show()
def plot_simmat(simmat,labfile=''): """ Plot a similarity matrix """ # postprocess simmat simmat2 = copy.deepcopy(simmat) if False: allvals = np.sort(simmat2.flatten()) medianval = allvals[int(allvals.shape[0]/2)] simmat2[np.where(simmat2>medianval)] = medianval # plot import pylab as P P.figure() args2 = {'interpolation':'nearest','cmap':P.cm.gray,'aspect':'auto'} P.imshow(simmat2,**args2) P.colorbar() P.hold(True) # we have labfile? if labfile != '': startbeats,stopbeats,labels = DUMMY.read_lab_file(labfile) for sb in startbeats: pos = sb assert pos <= simmat.shape[1],'wrong pos for lab data' point_size = 30 P.scatter(pos,pos,s=point_size,c='r',marker='o') P.scatter(pos,0,s=point_size,c='r',marker='o') P.scatter(0,pos,s=point_size,c='r',marker='o') P.hold(False) # diff simmat_diff = np.diff(simmat2) P.figure() args2 = {'interpolation':'nearest','cmap':P.cm.gray,'aspect':'auto'} P.imshow(simmat_diff,**args2) P.colorbar() P.hold(True) # we have labfile? if labfile != '': startbeats,stopbeats,labels = DUMMY.read_lab_file(labfile) for sb in startbeats: pos = sb - 1 assert pos <= simmat.shape[1],'wrong pos for lab data' point_size = 30 P.scatter(pos,pos,s=point_size,c='r',marker='o') P.scatter(pos,0,s=point_size,c='r',marker='o') P.scatter(0,pos,s=point_size,c='r',marker='o') P.hold(False) # show P.show()
def maxes_beattimes_segs_from_audiofile(wavfile): """ Utility function From a given eavfile: - computes the fingerprint maxes - gets the corresponding en beat times - gets the corresponding annotated segments RETURN: signal, sampling rate, maxes, beatstarts, duration, segstarts, labels """ # fingerprint it wav = LANDMARKS.AUDIOLAB.wavread(wavfile) L,S,T,maxes = LANDMARKS.find_landmarks(wav[0],wav[1]) # find the EN matfile relwavfile = os.path.relpath(wavfile,start=_audio_dir) enmatfile = os.path.join(_enfeats_dir,relwavfile+'.mat') assert os.path.exists(enmatfile),'can not find matfile %s' % enmatfile mat = sio.loadmat(enmatfile) btstart = mat['btstart'] try: duration = mat['duration'][0][0] # must be some bug in encoding except TypeError: duration = mat['duration'] # get the segments labfile = enmatfile+'.lab' assert os.path.exists(labfile),'can not find labfile %s' % labfile segstarts, segstops, labels = DUMMY.read_lab_file(labfile) # done, return return wav[0], wav[1], maxes, btstart, duration, segstarts, labels
def maxes_beattimes_segs_from_audiofile(wavfile): """ Utility function From a given eavfile: - computes the fingerprint maxes - gets the corresponding en beat times - gets the corresponding annotated segments RETURN: signal, sampling rate, maxes, beatstarts, duration, segstarts, labels """ # fingerprint it wav = LANDMARKS.AUDIOLAB.wavread(wavfile) L, S, T, maxes = LANDMARKS.find_landmarks(wav[0], wav[1]) # find the EN matfile relwavfile = os.path.relpath(wavfile, start=_audio_dir) enmatfile = os.path.join(_enfeats_dir, relwavfile + '.mat') assert os.path.exists(enmatfile), 'can not find matfile %s' % enmatfile mat = sio.loadmat(enmatfile) btstart = mat['btstart'] try: duration = mat['duration'][0][0] # must be some bug in encoding except TypeError: duration = mat['duration'] # get the segments labfile = enmatfile + '.lab' assert os.path.exists(labfile), 'can not find labfile %s' % labfile segstarts, segstops, labels = DUMMY.read_lab_file(labfile) # done, return return wav[0], wav[1], maxes, btstart, duration, segstarts, labels
def plot_simmat(data, winsize=1, overlap=0, dist=euclidean_dist, labfile=''): """ Similat to build_simmat, but plot it, and can add labfile information """ # get simmat simmat = build_simmat(data, winsize=winsize, overlap=overlap, dist=dist) # PLOT IT import pylab as P P.figure() args2 = {'interpolation': 'nearest', 'cmap': P.cm.gray, 'aspect': 'auto'} P.imshow(simmat, **args2) # we have labfile? if labfile != '': P.hold(True) startbeats, stopbeats, labels = DUMMY.read_lab_file(labfile) for sb in startbeats: pos = int((sb - winsize) / (winsize - overlap)) + 1 assert pos <= simmat.shape[1], 'wrong pos for lab data' point_size = 30 P.scatter(pos, pos, s=point_size, c='r', marker='o') P.scatter(pos, 0, s=point_size, c='r', marker='o') P.scatter(0, pos, s=point_size, c='r', marker='o') P.hold(False) P.show() # plot first derivative P.figure() simmat_diff = np.diff(simmat) simmat_diff = simmat_diff * simmat_diff P.imshow(simmat_diff, **args2) # we have labfile? if labfile != '': P.hold(True) startbeats, stopbeats, labels = DUMMY.read_lab_file(labfile) for sb in startbeats: pos = int((sb - winsize) / (winsize - overlap)) + 1 - 1 assert pos <= simmat.shape[1], 'wrong pos for lab data' point_size = 30 P.scatter(pos, pos, s=point_size, c='r', marker='o') P.scatter(pos, 0, s=point_size, c='r', marker='o') P.scatter(0, pos, s=point_size, c='r', marker='o') P.hold(False) P.show() # done, return simmat return simmat
def plot_simmat(data,winsize=1,overlap=0,dist=euclidean_dist,labfile=''): """ Similat to build_simmat, but plot it, and can add labfile information """ # get simmat simmat = build_simmat(data,winsize=winsize,overlap=overlap,dist=dist) # PLOT IT import pylab as P P.figure() args2 = {'interpolation':'nearest','cmap':P.cm.gray,'aspect':'auto'} P.imshow(simmat,**args2) # we have labfile? if labfile != '': P.hold(True) startbeats,stopbeats,labels = DUMMY.read_lab_file(labfile) for sb in startbeats: pos = int((sb - winsize) / (winsize - overlap)) + 1 assert pos <= simmat.shape[1],'wrong pos for lab data' point_size = 30 P.scatter(pos,pos,s=point_size,c='r',marker='o') P.scatter(pos,0,s=point_size,c='r',marker='o') P.scatter(0,pos,s=point_size,c='r',marker='o') P.hold(False) P.show() # plot first derivative P.figure() simmat_diff = np.diff(simmat) simmat_diff = simmat_diff * simmat_diff P.imshow(simmat_diff,**args2) # we have labfile? if labfile != '': P.hold(True) startbeats,stopbeats,labels = DUMMY.read_lab_file(labfile) for sb in startbeats: pos = int((sb - winsize) / (winsize - overlap)) + 1 - 1 assert pos <= simmat.shape[1],'wrong pos for lab data' point_size = 30 P.scatter(pos,pos,s=point_size,c='r',marker='o') P.scatter(pos,0,s=point_size,c='r',marker='o') P.scatter(0,pos,s=point_size,c='r',marker='o') P.hold(False) P.show() # done, return simmat return simmat
def plot_maxes_beats_segs(maxes,maxessecs,btstart,labfile=''): """ Plot the maxes for the whole songs, indicates beats and segs """ import pylab as P P.figure() P.hold(True) P.scatter(maxessecs,list(maxes[1,:]),c='b') #for bs in list(btstart.flatten()): # P.axvline(x=bs,color='r') if labfile != '': startbeats,stopbeats,labels = DUMMY.read_lab_file(labfile) for sb in startbeats: pos = btstart[0,sb] P.axvline(x=pos,color='g') P.hold(False) P.show()
def plot_nearby_diff(beatfeats,labfile='',dist=dist_avg_closest_pair): """ plot difference between nearby beats """ dists = map(lambda k: dist(beatfeats[k-1],beatfeats[k+1]),range(1,len(beatfeats)-1)) # plot import pylab as P P.plot(dists) P.hold(True) if labfile != '': startbeats,stopbeats,labels = DUMMY.read_lab_file(labfile) for sb in startbeats: pos = sb point_size = 30 P.scatter(pos,0,s=point_size,c='r',marker='o') P.hold(False) P.show()
def plot_maxes_beats_segs(maxes, maxessecs, btstart, labfile=''): """ Plot the maxes for the whole songs, indicates beats and segs """ import pylab as P P.figure() P.hold(True) P.scatter(maxessecs, list(maxes[1, :]), c='b') #for bs in list(btstart.flatten()): # P.axvline(x=bs,color='r') if labfile != '': startbeats, stopbeats, labels = DUMMY.read_lab_file(labfile) for sb in startbeats: pos = btstart[0, sb] P.axvline(x=pos, color='g') P.hold(False) P.show()
def plot_nearby_diff(beatfeats, labfile='', dist=dist_avg_closest_pair): """ plot difference between nearby beats """ dists = map(lambda k: dist(beatfeats[k - 1], beatfeats[k + 1]), range(1, len(beatfeats) - 1)) # plot import pylab as P P.plot(dists) P.hold(True) if labfile != '': startbeats, stopbeats, labels = DUMMY.read_lab_file(labfile) for sb in startbeats: pos = sb point_size = 30 P.scatter(pos, 0, s=point_size, c='r', marker='o') P.hold(False) P.show()