| Home | Trees | Indices | Help |
|
|---|
|
|
1 # 2 # Authors: Christopher Hanley 3 # Program: wfc3_input.py 4 # Purpose: Class used to model WFC3 specific instrument data. 5 from __future__ import division # confidence high 6 7 from pytools import fileutil 8 import numpy as np 9 from input_image import InputImage 1012 13 SEPARATOR = '_' 1414816 InputImage.__init__(self,input,dqname,platescale,memmap=0,proc_unit=proc_unit) 17 18 # define the cosmic ray bits value to use in the dq array 19 self.cr_bits_value = 4096 20 21 # Effective gain to be used in the driz_cr step. Since the 22 # WFC3 UVIS images have already been converted to electrons, 23 # the effective gain is 1. 24 self._effGain = 1 25 26 self.instrument = 'WFC3/UVIS' 27 self.full_shape = (4096,2051) 28 self.platescale = platescale 29 self.native_units = "electrons" 30 31 # get direction, which depends on which chip but is independent of amp 32 if ( self.extn == 'sci,1') : 33 self.cte_dir = -1 34 if ( self.extn == 'sci,2') : 35 self.cte_dir = 13638 _subarray = False 39 _ltv1 = float(fileutil.getKeyword(parlist['data'],'LTV1')) 40 _ltv2 = float(fileutil.getKeyword(parlist['data'],'LTV2')) 41 if (_ltv1 != 0.) or (_ltv2 != 0.): 42 _subarray = True 43 _naxis1 = float(fileutil.getKeyword(parlist['data'],'NAXIS1')) 44 _naxis2 = float(fileutil.getKeyword(parlist['data'],'NAXIS2')) 45 if (_naxis1 < self.full_shape[0]) or (_naxis2 < self.full_shape[0]): 46 _subarray = True 47 return _subarray4850 """ This method overrides the superclass to set default values into 51 the parameter dictionary, in case empty entries are provided. 52 """ 53 if self._isNotValid (instrpars['gain'], instrpars['gnkeyword']): 54 instrpars['gnkeyword'] = 'ATODGNA,ATODGNB,ATODGNC,ATODGND' 55 if self._isNotValid (instrpars['rdnoise'], instrpars['rnkeyword']): 56 instrpars['rnkeyword'] = 'READNSEA,READNSEB,READNSEC,READNSED' 57 if self._isNotValid (instrpars['exptime'], instrpars['expkeyword']): 58 instrpars['expkeyword'] = 'EXPTIME' 59 if instrpars['crbit'] == None: 60 instrpars['crbit'] = self.cr_bits_value 61 62 self._gain = self.getInstrParameter(instrpars['gain'], pri_header, 63 instrpars['gnkeyword']) 64 self._rdnoise = self.getInstrParameter(instrpars['rdnoise'], pri_header, 65 instrpars['rnkeyword']) 66 self._exptime = self.getInstrParameter(instrpars['exptime'], pri_header, 67 instrpars['expkeyword']) 68 self._crbit = instrpars['crbit'] 69 70 if self._gain == None or self._rdnoise == None or self._exptime == None: 71 print 'ERROR: invalid instrument task parameter' 72 raise ValueError 73 74 # Convert the science data to electrons if specified by the user. Each 75 # instrument class will need to define its own version of doUnitConversions 76 self.doUnitConversions()7779 """ 80 81 Purpose 82 ======= 83 Method for retrieving a detector's flat field. 84 85 This method will return an array the same shape as the 86 image. 87 88 :units: electrons 89 90 """ 91 92 # The keyword for WFC3 UVIS flat fields in the primary header of the flt 93 # file is pfltfile. This flat file is already in the required 94 # units of electrons. 95 96 filename = self.header['PFLTFILE'] 97 98 try: 99 handle = fileutil.openImage(filename,mode='readonly',memmap=0) 100 hdu = fileutil.getExtn(handle,extn=self.extn) 101 data = hdu.data[self.ltv2:self.size2,self.ltv1:self.size1] 102 except: 103 try: 104 handle = fileutil.openImage(filename[5:],mode='readonly',memmap=0) 105 hdu = fileutil.getExtn(handle,extn=self.extn) 106 data = hdu.data[self.ltv2:self.size2,self.ltv1:self.size1] 107 except: 108 data = np.ones(self.image_shape,dtype=self.image_dtype) 109 str = "Cannot find file "+filename+". Treating flatfield constant value of '1'.\n" 110 print str 111 flat = data 112 return flat113 114116 """ 117 118 Purpose 119 ======= 120 Return the dark current for the WFC3 UVIS detector. This value 121 will be contained within an instrument specific keyword. 122 The value is in units of electrons. 123 124 :units: electrons 125 126 """ 127 128 darkcurrent = 0 129 130 try: 131 darkcurrent = self.header['MEANDARK'] 132 except: 133 str = "#############################################\n" 134 str += "# #\n" 135 str += "# Error: #\n" 136 str += "# Cannot find the value for 'MEANDARK' #\n" 137 str += "# in the image header. WFC3 input images #\n" 138 str += "# are expected to have this header #\n" 139 str += "# keyword. #\n" 140 str += "# #\n" 141 str += "# Error occured in WFC3UVISInputImage class #\n" 142 str += "# #\n" 143 str += "#############################################\n" 144 raise ValueError, str 145 146 147 return darkcurrent150 151 SEPARATOR = '_' 152216154 InputImage.__init__(self,input,dqname,platescale,memmap=0,proc_unit=proc_unit) 155 156 # define the cosmic ray bits value to use in the dq array 157 self.cr_bits_value = 4096 158 159 # Effective gain to be used in the driz_cr step. Since the 160 # WFC3/IR images have already been converted to electrons the 161 # effective gain is 1. 162 self._effGain = 1 163 164 # no cte correction for WFC3/IR so set cte_dir=0. 165 self.cte_dir = 0 166 167 self.instrument = 'WFC3/IR' 168 self.full_shape = (1014,1014) 169 self.platescale = platescale 170 self.native_units = "ELECTRONS/S"171173 # Image information 174 _handle = fileutil.openImage(self.name,mode='update',memmap=0) 175 _sciext = fileutil.getExtn(_handle,extn=self.extn) 176 177 # Set the BUNIT keyword to 'electrons' 178 _sciext.header.update('BUNIT','ELECTRONS') 179 self.header.update('BUNIT','ELECTRONS') 180 181 # Counts case 182 np.multiply(_sciext.data,self.getExpTime(),_sciext.data) 183 184 # Close the files and clean-up 185 _handle.close()186 188 if (filename == None): 189 filename = self.name 190 try: 191 _handle = fileutil.openImage(filename,mode='update',memmap=0) 192 except IOError: 193 raise IOError, "Unable to open %s for sky level computation"%filename 194 # Get the exposure time for the image. If the exposure time of the image 195 # is 0, set the MDRIZSKY value to 0. Otherwise update the MDRIZSKY value 196 # in units of electrons per second. 197 if (self.getExpTime() == 0.0): 198 str = "*******************************************\n" 199 str += "* *\n" 200 str += "* ERROR: Image EXPTIME = 0. *\n" 201 str += "* MDRIZSKY header value cannot be *\n" 202 str += "* converted to units of 'electrons/s' *\n" 203 str += "* MDRIZSKY will be set to a value of '0' *\n" 204 str += "* *\n" 205 str = "*******************************************\n" 206 _handle[0].header['MDRIZSKY'] = 0 207 print str 208 else: 209 skyvalue = self.getSubtractedSky() 210 if self.proc_unit == 'electrons': 211 skyvalue = skyvalue / self.getExpTime() 212 213 print "Updating MDRIZSKY keyword to primary header with value %f"%(skyvalue) 214 _handle[0].header.update('MDRIZSKY',skyvalue) 215 _handle.close()218 """ This method overrides the superclass to set default values into 219 the parameter dictionary, in case empty entries are provided. 220 """ 221 if self._isNotValid (instrpars['gain'], instrpars['gnkeyword']): 222 instrpars['gnkeyword'] = 'ATODGNA,ATODGNB,ATODGNC,ATODGND' 223 if self._isNotValid (instrpars['rdnoise'], instrpars['rnkeyword']): 224 instrpars['rnkeyword'] = 'READNSEA,READNSEB,READNSEC,READNSED' 225 if self._isNotValid (instrpars['exptime'], instrpars['expkeyword']): 226 instrpars['expkeyword'] = 'EXPTIME' 227 if instrpars['crbit'] == None: 228 instrpars['crbit'] = self.cr_bits_value 229 230 self._gain = self.getInstrParameter(instrpars['gain'], pri_header, 231 instrpars['gnkeyword']) 232 self._rdnoise = self.getInstrParameter(instrpars['rdnoise'], pri_header, 233 instrpars['rnkeyword']) 234 self._exptime = self.getInstrParameter(instrpars['exptime'], pri_header, 235 instrpars['expkeyword']) 236 self._crbit = instrpars['crbit'] 237 238 if self._gain == None or self._rdnoise == None or self._exptime == None: 239 print 'ERROR: invalid instrument task parameter' 240 raise ValueError 241 242 self.doUnitConversions()243245 """ 246 247 Purpose 248 ======= 249 Method for retrieving a detector's flat field. 250 251 This method will return an array the same shape as the 252 image. 253 254 :units: electrons 255 256 """ 257 258 # The keyword for WFC3 IR flat fields in the primary header of the flt 259 # file is PFLTFILE. This flat file is not already in the required 260 # units of electrons. 261 262 filename = self.header['PFLTFILE'] 263 264 try: 265 handle = fileutil.openImage(filename,mode='readonly',memmap=0) 266 hdu = fileutil.getExtn(handle,extn=self.grp) 267 flat = hdu.data[self.ltv2:self.size2,self.ltv1:self.size1] 268 except: 269 try: 270 handle = fileutil.openImage(filename[5:],mode='readonly',memmap=0) 271 hdu = fileutil.getExtn(handle,extn=self.grp) 272 flat = hdu.data[self.ltv2:self.size2,self.ltv1:self.size1] 273 except: 274 flat = np.ones(self.image_shape,dtype=self.image_dtype) 275 str = "Cannot find file "+filename+". Treating flatfield constant value of '1'.\n" 276 print str 277 278 #flat = (1.0/data) # The flat field is normalized to unity. 279 280 return flat281283 """ 284 285 Purpose 286 ======= 287 Return an array representing the dark image for the detector. 288 289 :units: cps 290 291 """ 292 293 # First attempt to get the dark image specified by the "DARKFILE" 294 # keyword in the primary keyword of the science data. 295 try: 296 filename = self.header["DARKFILE"] 297 handle = fileutil.openImage(filename,mode='readonly',memmap=0) 298 hdu = fileutil.getExtn(handle,extn="sci") 299 darkobj = hdu.data[self.ltv2:self.size2,self.ltv1:self.size1] 300 # If the darkfile cannot be located, create the dark image from 301 # what we know about the detector dark current and assume a 302 # constant dark current for the whole image. 303 except: 304 darkobj = np.ones(self.image_shape,dtype=self.image_dtype)*self.getdarkcurrent() 305 return darkobj306 307309 """ 310 311 Purpose 312 ======= 313 Return the dark current for the WFC3/IR detector. This value 314 will be contained within an instrument specific keyword. 315 316 :units: electrons 317 318 """ 319 320 darkcurrent = 0 321 322 try: 323 darkcurrent = self.header['MEANDARK'] 324 except: 325 str = "#############################################\n" 326 str += "# #\n" 327 str += "# Error: #\n" 328 str += "# Cannot find the value for 'MEANDARK' #\n" 329 str += "# in the image header. WFC3 input images #\n" 330 str += "# are expected to have this header #\n" 331 str += "# keyword. #\n" 332 str += "# #\n" 333 str += "# Error occured in WFC3IRInputImage class #\n" 334 str += "# #\n" 335 str += "#############################################\n" 336 raise ValueError, str 337 338 339 return darkcurrent340
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Thu Jan 13 11:20:09 2011 | http://epydoc.sourceforge.net |