Coverage for soxspipe/recipes/soxs_mbias.py: 30%

# Coverage for soxspipe/recipes/soxs_mbias.py : 30%

## 56 statements 17 run 39 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*The recipe for creating master-bias frames *

5

6:Author:

7 David Young & Marco Landoni

8

9:Date Created:

10 January 22, 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 from soxspipe.commonutils import set_of_files

19 from ._base_recipe_ import _base_recipe_

20 import numpy as np

21 from astropy.nddata import CCDData

22 from astropy import units as u

23 import ccdproc

24 from soxspipe.commonutils import keyword_lookup

25

26

27 class soxs_mbias(_base_recipe_):

28 """

29 *The* `soxs_mbias` *recipe is used to generate a master-bias frame from a set of input raw bias frames. The recipe is used only for the UV-VIS arm as NIR frames have the bias (and dark current) removed by subtracting an off-frame of equal expsoure length.*

30

31 **Key Arguments**

32

33 - ``log`` -- logger

34 - ``settings`` -- the settings dictionary

35 - ``inputFrames`` -- input fits frames. Can be a directory, a set-of-files (SOF) file or a list of fits frame paths. Default: `[]`

36

37 **Usage**

38

39 ```python

40 from soxspipe.recipes import soxs_mbias

41 mbiasFrame = soxs_mbias(

42 log=log,

43 settings=settings,

44 inputFrames=fileList

45 ).produce_product()

46 ```

47

48 ```eval_rst

49 .. todo::

50 - add a tutorial about ``soxs_mbias`` to documentation

51 ```

52 """

53 # Initialisation

54

55 def __init__(

56 self,

57 log,

58 settings=False,

59 inputFrames=[]

60

61 ):

62 # INHERIT INITIALISATION FROM _base_recipe_

63 super(soxs_mbias, self).__init__(log=log, settings=settings)

64 self.log = log

65 log.debug("instansiating a new 'soxs_mbias' object")

66 self.settings = settings

67 self.inputFrames = inputFrames

68 # xt-self-arg-tmpx

69

70 # INITIAL ACTIONS

71 # CONVERT INPUT FILES TO A CCDPROC IMAGE COLLECTION (inputFrames >

72 # imagefilecollection)

73 sof = set_of_files(

74 log=self.log,

75 settings=self.settings,

76 inputFrames=self.inputFrames

77 )

78 self.inputFrames, self.supplementaryInput = sof.get()

79

80 # VERIFY THE FRAMES ARE THE ONES EXPECTED BY SOXS_MBIAS - NO MORE, NO LESS.

81 # PRINT SUMMARY OF FILES.

82 print("# VERIFYING INPUT FRAMES")

83 self.verify_input_frames()

84 sys.stdout.write("\x1b[1A\x1b[2K")

85 print("# VERIFYING INPUT FRAMES - ALL GOOD")

86

87 print("\n# RAW INPUT BIAS FRAMES - SUMMARY")

88 # SORT IMAGE COLLECTION

89 self.inputFrames.sort(['mjd-obs'])

90 print(self.inputFrames.summary, "\n")

91

92 # PREPARE THE FRAMES - CONVERT TO ELECTRONS, ADD UNCERTAINTY AND MASK

93 # EXTENSIONS

94 self.inputFrames = self.prepare_frames(

95 save=self.settings["save-intermediate-products"])

96

97 return None

98

99 def verify_input_frames(

100 self):

101 """*verify the input frame match those required by the soxs_mbias recipe*

102

103 If the fits files conform to required input for the recipe everything will pass silently, otherwise an exception shall be raised.

104 """

105 self.log.debug('starting the ``verify_input_frames`` method')

106

107 kw = self.kw

108

109 # BASIC VERIFICATION COMMON TO ALL RECIPES

110 self._verify_input_frames_basics()

111

112 imageTypes = self.inputFrames.values(

113 keyword=kw("DPR_TYPE").lower(), unique=True)

114 # MIXED INPUT IMAGE TYPES ARE BAD

115 if len(imageTypes) > 1:

116 imageTypes = " and ".join(imageTypes)

117 print(self.inputFrames.summary)

118 raise TypeError(

119 "Input frames are a mix of %(imageTypes)s" % locals())

120 # NON-BIAS INPUT IMAGE TYPES ARE BAD

121 elif imageTypes[0] != 'BIAS':

122 print(self.inputFrames.summary)

123 raise TypeError(

124 "Input frames not BIAS frames" % locals())

125

126 self.imageType = imageTypes[0]

127

128 self.log.debug('completed the ``verify_input_frames`` method')

129 return None

130

131 def produce_product(

132 self):

133 """*The code to generate the product of the soxs_mbias recipe*

134

135 **Return:**

136 - ``productPath`` -- the path to the final product

137 """

138 self.log.debug('starting the ``produce_product`` method')

139

140 arm = self.arm

141 kw = self.kw

142 dp = self.detectorParams

143

144 combined_bias_mean = self.clip_and_stack(

145 frames=self.inputFrames, recipe="soxs_mbias")

146

147 # INSPECTING THE THE UNCERTAINTY MAPS

148 # print("individual frame data")

149 # for a in ccds:

150 # print(a.data[0][0])

151 # print("\ncombined frame data")

152 # print(combined_bias_mean.data[0][0])

153 # print("individual frame error")

154 # for a in ccds:

155 # print(a.uncertainty[0][0])

156 # print("combined frame error")

157 # print(combined_bias_mean.uncertainty[0][0])

158

159 # combined_bias_mean.data = combined_bias_mean.data.astype('float32')

160 # combined_bias_mean.uncertainty = combined_bias_mean.uncertainty.astype(

161 # 'float32')

162

163 # WRITE TO DISK

164 productPath = self._write(

165 frame=combined_bias_mean,

166 filedir=self.intermediateRootPath,

167 filename=False,

168 overwrite=True

169 )

170

171 self.clean_up()

172

173 self.log.debug('completed the ``produce_product`` method')

174 return productPath

175

176 # use the tab-trigger below for new method

177 # xt-class-method