Coverage for python/lsst/verify/bin/print_metricvalues.py: 21%

29 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-18 10:07 +0000

1# This file is part of verify. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (http://www.lsst.org). 

6# See the COPYRIGHT file at the top-level directory of this distribution 

7# for details of code ownership. 

8# 

9# This program is free software: you can redistribute it and/or modify 

10# it under the terms of the GNU General Public License as published by 

11# the Free Software Foundation, either version 3 of the License, or 

12# (at your option) any later version. 

13# 

14# This program is distributed in the hope that it will be useful, 

15# but WITHOUT ANY WARRANTY; without even the implied warranty of 

16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

17# GNU General Public License for more details. 

18# 

19# You should have received a copy of the GNU General Public License 

20# along with this program. If not, see <http://www.gnu.org/licenses/>. 

21 

22"""Summarize measured metric values in one butler repo, or difference values 

23between two repos. 

24 

25This tool is built on the `~lsst.verify.extract_metricvalues` module, which 

26can be used to investigate metrics within e.g. a notebook environment. 

27""" 

28__all__ = ["main", "build_argparser"] 

29 

30import argparse 

31 

32import lsst.daf.butler 

33from .. import extract_metricvalues 

34 

35 

36def build_argparser(): 

37 """Return an ArgumentParser for this script. 

38 """ 

39 parser = argparse.ArgumentParser( 

40 description=__doc__, 

41 formatter_class=argparse.RawDescriptionHelpFormatter, 

42 epilog='More information is available at https://pipelines.lsst.io.') 

43 parser.add_argument("repo", type=str, 

44 help="Path to butler repo to load metrics from.") 

45 parser.add_argument("collection", type=str, 

46 help="Collection in REPO to load from.") 

47 parser.add_argument("repo2", type=str, nargs="?", default=None, 

48 help="Path to butler repo to load metrics from, to difference with REPO.") 

49 parser.add_argument("collection2", type=str, nargs="?", default=None, 

50 help="Collection in REPO2 to load from, otherwise use COLLECTION.") 

51 parser.add_argument("--kind", choices=["value", "timing", "memory"], default="value", 

52 help="What kind of metrics to load (default='value')." 

53 "Not supported when printing metric differences.") 

54 parser.add_argument("-v", "--verbose", action="store_true", 

55 help="Print extra information when loading metric values or handling errors.") 

56 parser.add_argument("--data-id-keys", nargs="+", default=None, 

57 help="Only print these dataId keys in the output;" 

58 "for example, `--data-id-keys detector visit`.") 

59 return parser 

60 

61 

62def main(): 

63 args = build_argparser().parse_args() 

64 

65 butler = lsst.daf.butler.Butler(args.repo, collections=args.collection) 

66 

67 if args.repo2 is None: 

68 extract_metricvalues.print_metrics(butler, 

69 args.kind, 

70 data_id_keys=args.data_id_keys, 

71 verbose=args.verbose) 

72 else: 

73 collection2 = args.collection2 if args.collection2 is not None else args.collection 

74 butler2 = lsst.daf.butler.Butler(args.repo2, collections=collection2) 

75 print("Printed values are `repo2 - repo1 = delta`, where:") 

76 print(f"repo2 = {args.repo2}#{collection2}") 

77 print(f"repo1 = {args.repo}#{args.collection}") 

78 if args.repo2 == args.repo: 

79 print(f"delta = ({collection2}) - ({args.collection})") 

80 else: 

81 print(f"delta = ({args.repo2}) - ({args.repo})") 

82 extract_metricvalues.print_diff_metrics(butler, 

83 butler2, 

84 data_id_keys=args.data_id_keys, 

85 verbose=args.verbose)