Coverage for soxspipe/commonutils/detector_lookup.py: 94%

# Coverage for soxspipe/commonutils/detector_lookup.py : 94%

## 31 statements 29 run 2 missing 0 excluded

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1#!/usr/bin/env python

2# encoding: utf-8

3"""

4*return a dictionary of detector characteristics and parameters*

5

6:Author:

7 David Young & Marco Landoni

8

9:Date Created:

10 August 13, 2020

11"""

12################# GLOBAL IMPORTS ####################

13 from builtins import object

14 import sys

15 import os

16 os.environ['TERM'] = 'vt100'

17 from fundamentals import tools

18

19

20 class detector_lookup(object):

21 """

22 *return a dictionary of detector characteristics and parameters*

23

24 **Key Arguments:**

25 - ``log`` -- logger

26 - ``settings`` -- the settings dictionary

27

28 **Usage:**

29

30 To initiate a detector_lookup object, use the following:

31

32 ```python

33 from soxspipe.commonutils import detector_lookup

34 detector = detector_lookup(

35 log=log,

36 settings=settings

37 ).get("NIR")

38 print(detector["science-pixels"])

39 ```

40

41 """

42

43 def __init__(

44 self,

45 log,

46 settings=False,

47 ):

48 self.log = log

49 log.debug("instansiating a new 'detector_lookup' object")

50 self.settings = settings

51

52 # SELECT THE INSTRUMENT AND READ THE KEYWORD DICTIONARY IN RESOURCES

53 # FOLDER

54 if "instrument" in settings:

55 self.instrument = settings["instrument"]

56 else:

57 self.instrument = "soxs"

58 self.dectDict = self._select_dictionary()

59

60 return None

61

62 def get(self,

63 arm):

64 """

65 *return a dictionary of detector characteristics and parameters*

66

67 **Key Arguments:**

68 - ``arm`` -- the detector parameters to return

69 """

70 self.log.debug('starting the ``get`` method')

71

72 arm = arm.upper()

73

74 if arm not in self.dectDict:

75 raise LookupError(f"the detector '{arm}' cannot be found in the detector parameters lookup file")

76

77 self.log.debug('completed the ``get`` method')

78 return self.dectDict[arm]

79

80 def _select_dictionary(

81 self):

82 """*select the detector parameter dictionary based on the instrument passed via the settings*

83

84 **Return:**

85 - ``dectDict`` -- the python dictionary of detector parameters

86

87 **Usage**

88

89 ```python

90 from soxspipe.commonutils import detector_lookup

91 detector = detector_lookup(

92 log=log,

93 settings=settings

94 )

95 dectDict = detector._select_dictionary()

96 ```

97 """

98 self.log.debug('starting the ``_select_dictionary`` method')

99

100 # GENERATE PATH TO YAML DICTIONARY

101 yamlFilePath = os.path.dirname(os.path.dirname(

102 __file__)) + "/resources/" + self.instrument + "_detector_parameters.yaml"

103

104 # YAML CONTENT TO DICTIONARY

105 import yaml

106 with open(yamlFilePath, 'r') as stream:

107 dectDict = yaml.load(stream)

108

109 self.log.debug('completed the ``_select_dictionary`` method')

110 return dectDict