Coverage for pesummary/gw/file/injection.py: 93.3%

15 statements  

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

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

2 

3from pesummary.core.file.injection import Injection 

4from pesummary.gw.file.standard_names import standard_names 

5 

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

7 

8 

9class GWInjection(Injection): 

10 """Class to handle injection information 

11 

12 Parameters 

13 ---------- 

14 parameters: list 

15 list of parameters 

16 samples: nd list 

17 list of samples for each parameter 

18 conversion: Bool, optional 

19 If True, convert all injection parameters 

20 conversion_kwargs: dict, optional 

21 kwargs that are passed to the `pesummary.gw.conversions.convert` 

22 function 

23 """ 

24 def __init__( 

25 self, *args, mapping=standard_names, conversion=True, 

26 conversion_kwargs={}, **kwargs 

27 ): 

28 super(GWInjection, self).__init__(*args, mapping=mapping, **kwargs) 

29 if conversion: 

30 from pesummary.gw.conversions import convert 

31 

32 converted = convert(self, **conversion_kwargs) 

33 if conversion_kwargs.get("return_kwargs", False): 

34 converted = converted[0] 

35 self.update(converted) 

36 

37 @classmethod 

38 def read( 

39 cls, path, conversion=True, conversion_kwargs={}, additional_xml_map={}, 

40 **kwargs 

41 ): 

42 """Read an injection file and initalize the Injection class 

43 

44 Parameters 

45 ---------- 

46 path: str 

47 Path to the injection file you wish to read 

48 conversion: Bool, optional 

49 If True, convert all injection parameters 

50 conversion_kwargs: dict, optional 

51 kwargs that are passed to the `pesummary.gw.conversions.convert` 

52 function 

53 **kwargs: dict 

54 All kwargs passed to the format specific read function 

55 """ 

56 return super(GWInjection, cls).read( 

57 path, conversion=conversion, conversion_kwargs=conversion_kwargs, 

58 mapping=standard_names, num=0, read_kwargs={ 

59 "additional_xml_map": additional_xml_map, 

60 "add_zero_likelihood": False 

61 } 

62 )