diff --git a/batbot/__init__.py b/batbot/__init__.py index 111778f..c415831 100644 --- a/batbot/__init__.py +++ b/batbot/__init__.py @@ -63,6 +63,7 @@ def pipeline( config=None, # classifier_thresh=classifier.CONFIGS[None]['thresh'], clean=True, + output_folder='.', ): """ Run the ML pipeline on a given WAV filepath and return the classification results @@ -93,7 +94,9 @@ def pipeline( tuple ( float, list ( dict ) ): classifier score, list of time windows """ # Generate spectrogram - output_paths, metadata_path, metadata = spectrogram.compute(filepath) + output_paths, metadata_path, metadata = spectrogram.compute( + filepath, output_folder=output_folder + ) return output_paths, metadata_path @@ -161,7 +164,7 @@ def example(): assert exists(wav_filepath) log.debug(f'Running pipeline on WAV: {wav_filepath}') - - results = pipeline(wav_filepath) + output = './output' + results = pipeline(wav_filepath, output_folder=output) log.debug(results) diff --git a/batbot/batbot.py b/batbot/batbot.py index b47eb61..fa137e0 100755 --- a/batbot/batbot.py +++ b/batbot/batbot.py @@ -47,8 +47,9 @@ def fetch(config): ) @click.option( '--output', - help='Path to output JSON (if unspecified, results are printed to screen)', - default=None, + 'output_path', + help='Path to output folder for the results', + default='.', type=str, ) # @click.option( @@ -60,7 +61,7 @@ def fetch(config): def pipeline( filepath, config, - output, + output_path, # classifier_thresh, ): """ @@ -79,25 +80,13 @@ def pipeline( config = config.strip().lower() # classifier_thresh /= 100.0 - score = batbot.pipeline( + batbot.pipeline( filepath, config=config, # classifier_thresh=classifier_thresh, + output_folder=output_path, ) - data = { - filepath: { - 'classifier': score, - } - } - - log.debug('Outputting results...') - if output: - with open(output, 'w') as outfile: - json.dump(data, outfile) - else: - print(data) - @click.command('batch') @click.argument( diff --git a/batbot/spectrogram/__init__.py b/batbot/spectrogram/__init__.py index b9814a0..f1fa0f4 100644 --- a/batbot/spectrogram/__init__.py +++ b/batbot/spectrogram/__init__.py @@ -1329,6 +1329,11 @@ def compute_wrapper( chunksize = int(50e3) + # create output folder if it doesn't exist + if not os.path.exists(output_folder): + os.makedirs(output_folder) + assert exists(output_folder) + debug_path = get_debug_path(output_folder, wav_filepath, enabled=debug) # Load the spectrogram from a WAV file on disk diff --git a/tests/test_spectrogram.py b/tests/test_spectrogram.py index dcf03d5..47fc1dc 100644 --- a/tests/test_spectrogram.py +++ b/tests/test_spectrogram.py @@ -5,4 +5,5 @@ def test_spectrogram_compute(): from batbot.spectrogram import compute wav_filepath = abspath(join('examples', 'example2.wav')) - output_paths, metadata_path, metadata = compute(wav_filepath) + output_folder = './output' + output_paths, metadata_path, metadata = compute(wav_filepath, output_folder=output_folder)