Coverage for pesummary/cli/summarygracedb.py: 90.5%

21 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-05-02 08:42 +0000

1#! /usr/bin/env python 

2 

3# Licensed under an MIT style license -- see LICENSE.md 

4 

5from pesummary.core.cli.parser import ArgumentParser as _ArgumentParser 

6 

7__author__ = ["Charlie Hoy <charlie.hoy@ligo.org>"] 

8 

9 

10class ArgumentParser(_ArgumentParser): 

11 def _pesummary_options(self): 

12 options = super(ArgumentParser, self)._pesummary_options() 

13 options.update( 

14 { 

15 "--id": { 

16 "required": True, 

17 "help": "The GraceDB id of the event you are interested in", 

18 }, 

19 "--info": { 

20 "nargs": "+", 

21 "help": "Specific information you wish to retrieve", 

22 }, 

23 "--output": { 

24 "short": "-o", 

25 "help": "Output json file you wish to save the data to", 

26 }, 

27 } 

28 ) 

29 return options 

30 

31 

32def main(args=None): 

33 """ 

34 """ 

35 from pesummary.gw.gracedb import get_gracedb_data 

36 

37 _parser = ArgumentParser(description=__doc__) 

38 _parser.add_known_options_to_parser(["--id", "--info", "--output"]) 

39 opts, unknown = _parser.parse_known_args(args=args) 

40 data = get_gracedb_data(opts.id, info=opts.info) 

41 if opts.output is not None: 

42 import json 

43 

44 with open(opts.output, "w") as f: 

45 json.dump(data, f) 

46 return 

47 print(data) 

48 

49 

50if __name__ == "__main__": 

51 main()