Skip to content

Commit 0fdf8b9

Browse files
Merge pull request #7 from Kitware/issue-4-output-folder-option
Output folder option
2 parents ee1c09b + b93f23e commit 0fdf8b9

4 files changed

Lines changed: 19 additions & 21 deletions

File tree

batbot/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def pipeline(
6363
config=None,
6464
# classifier_thresh=classifier.CONFIGS[None]['thresh'],
6565
clean=True,
66+
output_folder='.',
6667
):
6768
"""
6869
Run the ML pipeline on a given WAV filepath and return the classification results
@@ -93,7 +94,9 @@ def pipeline(
9394
tuple ( float, list ( dict ) ): classifier score, list of time windows
9495
"""
9596
# Generate spectrogram
96-
output_paths, metadata_path, metadata = spectrogram.compute(filepath)
97+
output_paths, metadata_path, metadata = spectrogram.compute(
98+
filepath, output_folder=output_folder
99+
)
97100

98101
return output_paths, metadata_path
99102

@@ -161,7 +164,7 @@ def example():
161164
assert exists(wav_filepath)
162165

163166
log.debug(f'Running pipeline on WAV: {wav_filepath}')
164-
165-
results = pipeline(wav_filepath)
167+
output = './output'
168+
results = pipeline(wav_filepath, output_folder=output)
166169

167170
log.debug(results)

batbot/batbot.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ def fetch(config):
4747
)
4848
@click.option(
4949
'--output',
50-
help='Path to output JSON (if unspecified, results are printed to screen)',
51-
default=None,
50+
'output_path',
51+
help='Path to output folder for the results',
52+
default='.',
5253
type=str,
5354
)
5455
# @click.option(
@@ -60,7 +61,7 @@ def fetch(config):
6061
def pipeline(
6162
filepath,
6263
config,
63-
output,
64+
output_path,
6465
# classifier_thresh,
6566
):
6667
"""
@@ -79,25 +80,13 @@ def pipeline(
7980
config = config.strip().lower()
8081
# classifier_thresh /= 100.0
8182

82-
score = batbot.pipeline(
83+
batbot.pipeline(
8384
filepath,
8485
config=config,
8586
# classifier_thresh=classifier_thresh,
87+
output_folder=output_path,
8688
)
8789

88-
data = {
89-
filepath: {
90-
'classifier': score,
91-
}
92-
}
93-
94-
log.debug('Outputting results...')
95-
if output:
96-
with open(output, 'w') as outfile:
97-
json.dump(data, outfile)
98-
else:
99-
print(data)
100-
10190

10291
@click.command('batch')
10392
@click.argument(

batbot/spectrogram/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,11 @@ def compute_wrapper(
13291329

13301330
chunksize = int(50e3)
13311331

1332+
# create output folder if it doesn't exist
1333+
if not os.path.exists(output_folder):
1334+
os.makedirs(output_folder)
1335+
assert exists(output_folder)
1336+
13321337
debug_path = get_debug_path(output_folder, wav_filepath, enabled=debug)
13331338

13341339
# Load the spectrogram from a WAV file on disk

tests/test_spectrogram.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ def test_spectrogram_compute():
55
from batbot.spectrogram import compute
66

77
wav_filepath = abspath(join('examples', 'example2.wav'))
8-
output_paths, metadata_path, metadata = compute(wav_filepath)
8+
output_folder = './output'
9+
output_paths, metadata_path, metadata = compute(wav_filepath, output_folder=output_folder)

0 commit comments

Comments
 (0)