Mercurial > hg > plosone_underreview
comparison scripts/load_features.py @ 6:a35bd818d8e9 branch-tests
notebook to test music segments
author | Maria Panteli <m.x.panteli@gmail.com> |
---|---|
date | Mon, 11 Sep 2017 14:22:17 +0100 |
parents | e50c63cf96be |
children | 56cbf155680a 852d4377f6ca |
comparison
equal
deleted
inserted
replaced
5:543744ed1ae7 | 6:a35bd818d8e9 |
---|---|
78 music_bounds = np.where(bounds[:, 2] == 'm')[0] | 78 music_bounds = np.where(bounds[:, 2] == 'm')[0] |
79 bounds_in_frames = np.round(np.array(bounds[:, 0], dtype=float) * sr) | 79 bounds_in_frames = np.round(np.array(bounds[:, 0], dtype=float) * sr) |
80 duration_in_frames = np.round(np.array(bounds[:, 1], dtype=float) * sr) | 80 duration_in_frames = np.round(np.array(bounds[:, 1], dtype=float) * sr) |
81 for music_bound in music_bounds: | 81 for music_bound in music_bounds: |
82 lower_bound = np.max([0, bounds_in_frames[music_bound] - half_win_hop]) | 82 lower_bound = np.max([0, bounds_in_frames[music_bound] - half_win_hop]) |
83 upper_bound = lower_bound + duration_in_frames[music_bound] - half_win_hop | 83 upper_bound = bounds_in_frames[music_bound] + duration_in_frames[music_bound] - half_win_hop |
84 music_idx.append(np.arange(lower_bound, upper_bound, dtype=int)) | 84 music_idx.append(np.arange(lower_bound, upper_bound, dtype=int)) |
85 if len(music_idx)>0: | 85 if len(music_idx)>0: |
86 music_idx = np.sort(np.concatenate(music_idx)) # it should be sorted, but just in case segments overlap -- remove duplicates if segments overlap | 86 music_idx = np.sort(np.concatenate(music_idx)) # it should be sorted, but just in case segments overlap -- remove duplicates if segments overlap |
87 return music_idx | 87 return music_idx |
88 | 88 |
89 | 89 |
90 def get_music_idx_for_file(self, segmenter_file=None): | 90 def get_music_idx_for_file(self, segmenter_file=None): |
91 music_idx = [] | 91 music_idx = [] |
92 if os.path.exists(segmenter_file) and os.path.getsize(segmenter_file)>0: | 92 if os.path.exists(segmenter_file) and os.path.getsize(segmenter_file)>0: |
93 print 'loading speech/music segments...' | 93 print 'loading speech/music segments...' |
253 if scale: | 253 if scale: |
254 # scale all frames by mean and std of recording | 254 # scale all frames by mean and std of recording |
255 pbihist = (pbihist - np.nanmean(pbihist)) / np.nanstd(pbihist) | 255 pbihist = (pbihist - np.nanmean(pbihist)) / np.nanstd(pbihist) |
256 return pbihist | 256 return pbihist |
257 | 257 |
258 | |
259 # def get_pb_chroma_for_file(self, chroma_file=None, scale=True): | |
260 # ch = [] | |
261 # pb = [] | |
262 # if not os.path.exists(chroma_file): | |
263 # return ch, pb | |
264 # songframes = pd.read_csv(chroma_file, engine="c", header=None) | |
265 # songframes.iloc[np.where(np.isnan(songframes))] = 0 | |
266 # songframes = songframes.iloc[0:min(len(songframes), 18000), :] # only first 1.5 minutes | |
267 # chroma = songframes.get_values().T | |
268 # ch = self.get_ave_chroma(chroma) | |
269 # pb = self.get_pbihist_from_chroma(chroma) | |
270 # if scale: | |
271 # # scale all frames by mean and std of recording | |
272 # ch = (ch - np.nanmean(ch)) / np.nanstd(ch) | |
273 # pb = (pb - np.nanmean(pb)) / np.nanstd(pb) | |
274 # return ch, pb | |
275 | |
276 | |
277 # def get_pbihist_from_chroma(self, chroma, alignchroma=True, nmfpb=True): | |
278 # pb = pbi.PitchBihist(win2sec=self.win2sec) | |
279 # chroma[np.where(np.isnan(chroma))] = 0 | |
280 # if alignchroma: | |
281 # maxind = np.argmax(np.sum(chroma, axis=1)) | |
282 # chroma = np.roll(chroma, -maxind, axis=0) | |
283 # pbihist = pb.get_pitchbihist_from_chroma(chroma=chroma, chromasr=self.framessr) | |
284 # if nmfpb is True: | |
285 # pbihist = self.nmfpitchbihist(pbihist) | |
286 # pbihist = pd.DataFrame(pbihist.T) | |
287 # return pbihist |