Skip to content
Snippets Groups Projects
Commit b66c0d27 authored by ferrari's avatar ferrari
Browse files

Add a resume option

parent fdf067b6
Branches
No related tags found
No related merge requests found
...@@ -707,10 +707,22 @@ def main(args): ...@@ -707,10 +707,22 @@ def main(args):
outpath = args.input.rsplit('.', 1)[0] + '.pred.h5' outpath = args.input.rsplit('.', 1)[0] + '.pred.h5'
else: else:
outpath = args.out outpath = args.out
if os.path.isfile(outpath) and not args.erase: if os.path.isfile(outpath):
if not (args.erase or args.resume):
print(f'Out file {outpath} already exist and erase option isn\'t set.') print(f'Out file {outpath} already exist and erase option isn\'t set.')
return 1 return 1
elif args.resume:
print(f'Out file {outpath} does not already exist and resume option is set.')
return 1
ref_dict = init(args.input, args.channel) ref_dict = init(args.input, args.channel)
if args.resume:
df = pd.read_hdf(outpath)
ref_dict['callback'].df = df.to_dict(orient='index')
ref_dict['callback'].offset = np.tile(np.array(list(ref_dict['callback'].df.keys()))[:, np.newaxis], (1,2))
ref_dict['callback'].offset[:, 1] = ref_dict['callback'].song_resample[(ref_dict['callback'].offset[:, 1] * FSSR).astype(int)]
ref_dict['callback'].scat.set_offsets(ref_dict['callback'].offset)
ref_dict['callback'].scat.set_color(np.array(len(ref_dict['callback'].offset)*[[0.7, 0.2, 0.5, 1]]))
plt.draw() plt.draw()
plt.pause(0.2) plt.pause(0.2)
ref_dict['fig'].set_constrained_layout(False) ref_dict['fig'].set_constrained_layout(False)
...@@ -732,8 +744,11 @@ if __name__ == '__main__': ...@@ -732,8 +744,11 @@ if __name__ == '__main__':
parser.add_argument("input", type=str, help="Input file") parser.add_argument("input", type=str, help="Input file")
parser.add_argument("--out", type=str, default='', help="Output file. Default to the input_path'.pred.h5'") parser.add_argument("--out", type=str, default='', help="Output file. Default to the input_path'.pred.h5'")
parser.add_argument("--channel", type=int, default=0, help="Sound channel to be analysed. Indices start from 0.") parser.add_argument("--channel", type=int, default=0, help="Sound channel to be analysed. Indices start from 0.")
parser.add_argument("--erase", action='store_true', help="If out file exist and this option is not given," group = parser.add_mutually_exclusive_group()
group.add_argument("--erase", action='store_true', help="If out file exist and this option is not given,"
" the computation will be halted") " the computation will be halted")
group.add_argument("--resume", action='store_true', help="If out file exist and this option is given,"
" the previous annotation file will be loaded")
try: try:
args = parser.parse_args() args = parser.parse_args()
except ValueError as e: except ValueError as e:
...@@ -756,6 +771,10 @@ if __name__ == '__main__': ...@@ -756,6 +771,10 @@ if __name__ == '__main__':
self.out = input("What is the out file path? (Leave empty for default)") self.out = input("What is the out file path? (Leave empty for default)")
self.channel = int(input("Which channel do you want to use starting from 0? ")) self.channel = int(input("Which channel do you want to use starting from 0? "))
self.erase = ask("Do you want to erase the out file if it already exist?") self.erase = ask("Do you want to erase the out file if it already exist?")
if not self.erase:
self.resume = ask("Do you want to resume the out file if it already exist?")
else:
self.resume = False
args = VirtualArgParse() args = VirtualArgParse()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment