From b0da5e062327e07ecd3b3f2a4c9a88f9f9a59121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dion=20H=C3=A4fner?= Date: Thu, 29 Oct 2020 12:42:13 +0100 Subject: [PATCH] ensure output files are written --- fowd/processing.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/fowd/processing.py b/fowd/processing.py index d5cad1e..72894eb 100644 --- a/fowd/processing.py +++ b/fowd/processing.py @@ -213,8 +213,13 @@ def handle_output(wave_records, wave_params_history, num_flags_fired): wave_records_np[key] = np.asarray(val) # dump results to files - with open(outfile, 'ab') as f: - pickle.dump(wave_records_np, f) + if not os.path.exists(outfile): + with open(outfile, 'wb'): + pass + + if wave_records_np: + with open(outfile, 'ab') as f: + pickle.dump(wave_records_np, f) with open(statefile, 'wb') as f: pickle.dump({ @@ -255,6 +260,9 @@ def handle_output(wave_records, wave_params_history, num_flags_fired): ) with strict_filelock(outfile), tqdm.tqdm(**pbar_kwargs) as pbar: + # initialize output files + handle_output(wave_records, wave_params_history, num_flags_fired) + for wave_start, wave_stop in find_wave_indices(elevation_normalized, start_idx=start_idx): pbar.update(wave_stop - last_wave_stop) last_wave_stop = wave_stop