Hide keyboard shortcuts

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 to generate a master dark frame* 

5 

6:Author: 

7 David Young & Marco Landoni 

8 

9:Date Created: 

10 January 27, 2020 

11""" 

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

13from builtins import object 

14import sys 

15import os 

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

17from fundamentals import tools 

18from soxspipe.commonutils import set_of_files 

19from ._base_recipe_ import _base_recipe_ 

20import numpy as np 

21from astropy.nddata import CCDData 

22import ccdproc 

23from soxspipe.commonutils import keyword_lookup 

24 

25 

26class soxs_mdark(_base_recipe_): 

27 """ 

28 *The soxs_mdark recipe* 

29 

30 **Key Arguments** 

31 

32 - ``log`` -- logger 

33 - ``settings`` -- the settings dictionary 

34 - ``inputFrames`` -- input fits frames. Can be a directory, a set-of-files (SOF) file or a list of fits frame paths. 

35 

36 **Usage** 

37 

38 ```python 

39 from soxspipe.recipes import soxs_mdark 

40 mdarkFrame = soxs_mdark( 

41 log=log, 

42 settings=settings, 

43 inputFrames=fileList 

44 )..produce_product() 

45 ``` 

46 

47 ```eval_rst 

48 .. todo:: 

49 

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

51 ``` 

52 """ 

53 

54 def __init__( 

55 self, 

56 log, 

57 settings=False, 

58 inputFrames=[] 

59 

60 ): 

61 # INHERIT INITIALISATION FROM _base_recipe_ 

62 super(soxs_mdark, self).__init__(log=log, settings=settings) 

63 self.log = log 

64 log.debug("instansiating a new 'soxs_mdark' object") 

65 self.settings = settings 

66 self.inputFrames = inputFrames 

67 # xt-self-arg-tmpx 

68 

69 # INITIAL ACTIONS 

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

71 # imagefilecollection) 

72 sof = set_of_files( 

73 log=self.log, 

74 settings=self.settings, 

75 inputFrames=self.inputFrames 

76 ) 

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

78 

79 # VERIFY THE FRAMES ARE THE ONES EXPECTED BY SOXS_MDARK - NO MORE, NO LESS. 

80 # PRINT SUMMARY OF FILES. 

81 print("# VERIFYING INPUT FRAMES") 

82 self.verify_input_frames() 

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

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

85 

86 print("\n# RAW INPUT DARK FRAMES - SUMMARY") 

87 # SORT IMAGE COLLECTION 

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

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

90 

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

92 # EXTENSIONS 

93 self.inputFrames = self.prepare_frames( 

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

95 

96 return None 

97 

98 def verify_input_frames( 

99 self): 

100 """*verify the input frame match those required by the soxs_mdark recipe* 

101 

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

103 """ 

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

105 

106 kw = self.kw 

107 

108 # BASIC VERIFICATION COMMON TO ALL RECIPES 

109 self._verify_input_frames_basics() 

110 

111 imageTypes = self.inputFrames.values( 

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

113 # MIXED INPUT IMAGE TYPES ARE BAD 

114 if len(imageTypes) > 1: 

115 imageTypes = " and ".join(imageTypes) 

116 print(self.inputFrames.summary) 

117 raise TypeError( 

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

119 # NON-BIAS INPUT IMAGE TYPES ARE BAD 

120 elif imageTypes[0] != 'DARK': 

121 print(self.inputFrames.summary) 

122 raise TypeError( 

123 "Input frames not DARK frames" % locals()) 

124 

125 exptimes = self.inputFrames.values( 

126 keyword=kw("EXPTIME").lower(), unique=True) 

127 # MIXED INPUT IMAGE TYPES ARE BAD 

128 if len(exptimes) > 1: 

129 exptimes = [str(e) for e in exptimes] 

130 exptimes = " and ".join(exptimes) 

131 print(self.inputFrames.summary) 

132 raise TypeError( 

133 "Input frames have differing exposure-times %(exptimes)s" % locals()) 

134 

135 self.imageType = imageTypes[0] 

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

137 return None 

138 

139 def produce_product( 

140 self): 

141 """*The code to generate the product of the soxs_mdark recipe* 

142 

143 **Return:** 

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

145 """ 

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

147 

148 arm = self.arm 

149 kw = self.kw 

150 dp = self.detectorParams 

151 

152 combined_bias_mean = self.clip_and_stack( 

153 frames=self.inputFrames, recipe="soxs_mdark") 

154 

155 # WRITE TO DISK 

156 productPath = self._write( 

157 frame=combined_bias_mean, 

158 filedir=self.intermediateRootPath, 

159 filename=False, 

160 overwrite=True 

161 ) 

162 self.clean_up() 

163 

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

165 return productPath 

166 

167 # use the tab-trigger below for new method 

168 # xt-class-method