diff --git a/IPI_bombyx.py b/IPI_bombyx.py index 7ef44bb2336bca1bcf2b99bdc5cab07d99e07771..91eca4be1f61e338ad36bc9a06ca11243455e1ed 100644 --- a/IPI_bombyx.py +++ b/IPI_bombyx.py @@ -15,12 +15,14 @@ class BetterIter(object): self.max_num = len(to_wrap) self.to_wrap = to_wrap self.overlap = False + self.curr_len = None def __iter__(self): return self - def _test_done(self ,list_pass): - self.overlap = len(list_pass) >= self.max_num + def _test_done(self, list_pass): + self.curr_len = len(list_pass) + self.overlap = self.curr_len >= self.max_num def __next__(self): while True: @@ -39,7 +41,7 @@ class BetterIter(object): return val -def _next_file(event, refs, order, df, save, args, outpath, done_file): +def _next_file(event, refs, order, df, save, args, outpath, done_file, text): tmp = pd.DataFrame.from_dict(refs['callback'].df, orient='index') ind = order.current tmp['file'] = df.iloc[ind].filepredmax @@ -57,9 +59,10 @@ def _next_file(event, refs, order, df, save, args, outpath, done_file): try: ipi.reset(refs['callback'], os.path.join(args.wd, df.iloc[ind].filepredmax.strip('/')), args.channel) refs['fig'].canvas.set_window_title('IPI of ' + df.iloc[ind].filepredmax.rsplit('/', 1)[-1]) + text.set_text('{order.curr_len} files done') except (RuntimeError,FileNotFoundError) as e: print(e, 'Opening next file') - _next_file(event, refs, order, df, save, args, outpath, done_file) + _next_file(event, refs, order, df, save, args, outpath, done_file, text) @@ -94,8 +97,11 @@ def main(args): print(e, 'Opening next file') ind = samples_order.__next__() ref_dict = ipi.init(os.path.join(args.wd, df.iloc[ind].filepredmax.strip('/')), args.channel) + text_ax = plt.subplot(ref_dict['gridspec'][-1, -4:-2]) + text = text_ax.text(0.5, 0.5, f'{len(file_list)} files done', horizontalalignment='center', + verticalalignment='center', transform=text_ax.transAxes) next_file = partial(_next_file, refs=ref_dict, order=samples_order, df=df, save=save, args=args, outpath=outpath, - done_file=done_file) + done_file=done_file, text=text) next_ax = plt.subplot(ref_dict['gridspec'][-1, -2:]) next_button = Button(next_ax, 'Next file') next_button.on_clicked(next_file) diff --git a/ipi_extract.py b/ipi_extract.py index f4d198e3e2052c010299fde613f9f7990764d17e..14a7f85b261e5b4e9650a5701feb8601ef553fc4 100644 --- a/ipi_extract.py +++ b/ipi_extract.py @@ -402,7 +402,7 @@ class Callback(object): def play(self, event): sound = (norm(self.song_resample[self.p:self.p+FSSR*20])*(2**15-1)).astype(np.int16) try: - play(AudioSegment(sound.tobytes(), frame_rate=self.sr, sample_width=sound.dtype.itemsize, channels=1)) + play(AudioSegment(sound.tobytes(), frame_rate=FSSR, sample_width=sound.dtype.itemsize, channels=1)) except KeyboardInterrupt: pass