Coverage for src/bob/bio/base/script/sort.py: 100%
16 statements
« prev ^ index » next coverage.py v7.6.0, created at 2024-07-12 22:15 +0200
« prev ^ index » next coverage.py v7.6.0, created at 2024-07-12 22:15 +0200
1"""Sorts score files based on their score value
2"""
3import logging
5import click
6import numpy
8from clapper.click import log_parameters, verbosity_option
10from bob.bio.base.score.load import dump_score, load_score
12logger = logging.getLogger(__name__)
15@click.command(
16 epilog="""\b
17Examples:
19 $ bob bio sort -vvv /path/to/scores
20"""
21)
22@click.argument(
23 "score_paths",
24 type=click.Path(exists=True, file_okay=True, dir_okay=False, writable=True),
25 nargs=-1,
26)
27@verbosity_option(logger=logger)
28def sort(score_paths, **kwargs):
29 """Sorts score files based on their score values
31 The conversion happens in-place; backup your scores before using this script
32 """
33 log_parameters(logger)
35 for path in score_paths:
36 logger.info("Sorting: %s", path)
37 scores = load_score(path)
38 scores = scores[numpy.argsort(scores["score"])]
39 dump_score(path, scores)