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

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 *
6:Author:
7 David Young & Marco Landoni
9:Date Created:
10 January 22, 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
22from astropy import units as u
23import ccdproc
24from soxspipe.commonutils import keyword_lookup
27class 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.*
31 **Key Arguments**
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: `[]`
37 **Usage**
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 ```
48 ```eval_rst
49 .. todo::
50 - add a tutorial about ``soxs_mbias`` to documentation
51 ```
52 """
53 # Initialisation
55 def __init__(
56 self,
57 log,
58 settings=False,
59 inputFrames=[]
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
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()
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")
87 print("\n# RAW INPUT BIAS FRAMES - SUMMARY")
88 # SORT IMAGE COLLECTION
89 self.inputFrames.sort(['mjd-obs'])
90 print(self.inputFrames.summary, "\n")
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"])
97 return None
99 def verify_input_frames(
100 self):
101 """*verify the input frame match those required by the soxs_mbias recipe*
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')
107 kw = self.kw
109 # BASIC VERIFICATION COMMON TO ALL RECIPES
110 self._verify_input_frames_basics()
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())
126 self.imageType = imageTypes[0]
128 self.log.debug('completed the ``verify_input_frames`` method')
129 return None
131 def produce_product(
132 self):
133 """*The code to generate the product of the soxs_mbias recipe*
135 **Return:**
136 - ``productPath`` -- the path to the final product
137 """
138 self.log.debug('starting the ``produce_product`` method')
140 arm = self.arm
141 kw = self.kw
142 dp = self.detectorParams
144 combined_bias_mean = self.clip_and_stack(
145 frames=self.inputFrames, recipe="soxs_mbias")
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])
159 # combined_bias_mean.data = combined_bias_mean.data.astype('float32')
160 # combined_bias_mean.uncertainty = combined_bias_mean.uncertainty.astype(
161 # 'float32')
163 # WRITE TO DISK
164 productPath = self._write(
165 frame=combined_bias_mean,
166 filedir=self.intermediateRootPath,
167 filename=False,
168 overwrite=True
169 )
171 self.clean_up()
173 self.log.debug('completed the ``produce_product`` method')
174 return productPath
176 # use the tab-trigger below for new method
177 # xt-class-method