Package multidrizzle :: Module mdzhandler
[hide private]
[frames] | no frames]

Source Code for Module multidrizzle.mdzhandler

 1  # 
 2  #   Authors: Warren Hack, Ivo Busko, Christopher Hanley 
 3  #   Program: mdzhandler.py 
 4  #   Purpose: Module that handles the MDRIZTAB reference file. 
 5  from __future__ import division # confidence high 
 6   
 7  import pyfits 
 8  from pytools import fileutil 
 9   
10   
11 -def getMultidrizzleParameters(files):
12 """ Gets entry in MDRIZTAB where task parameters live. 13 This method returns a record array mapping the selected 14 row. 15 """ 16 17 # Get the MDRIZTAB table file name from the primary header. 18 # It is gotten from the first file in the input list. No 19 # consistency checks are performed. 20 _fileName = files[0] 21 _header = fileutil.getHeader(_fileName) 22 if _header.has_key('MDRIZTAB'): 23 _tableName = _header['MDRIZTAB'] 24 else: 25 raise KeyError, "No MDRIZTAB found in file " + _fileName 26 27 _tableName = fileutil.osfn(_tableName) 28 29 # Now get the filters from the primary header. 30 _filters = fileutil.getFilterNames(_header) 31 32 # Open MDRIZTAB file. 33 try: 34 _mdriztab = pyfits.open(_tableName) 35 except: 36 raise IOError,"MDRIZTAB table '%s' not valid!" % _tableName 37 38 # Look for matching rows based on filter name. If no 39 # match, pick up rows for the default filter. 40 _rows = _getRowsByFilter(_mdriztab, _filters) 41 if _rows == []: 42 _rows = _getRowsByFilter(_mdriztab, 'ANY') 43 44 # Now look for the row that matches the number of images. 45 # The logic below assumes that rows for a given filter 46 # are arranged in ascending order of the 'numimage' field. 47 _nimages = len(files) 48 _row = 0 49 for i in _rows: 50 _numimages = _mdriztab[1].data.field('numimages')[i] 51 if _nimages >= _numimages: 52 _row = i 53 print '- MDRIZTAB: MultiDrizzle parameters read from row %s.'%(_row+1) 54 55 mpars = _mdriztab[1].data[_row] 56 _mdriztab.close() 57 58 return mpars
59
60 -def _getRowsByFilter(table, filters):
61 rows = [] 62 for i in xrange(table[1].data.shape[0]): 63 _tfilters = table[1].data.field('filter')[i] 64 if _tfilters == filters: 65 rows.append(i) 66 return rows
67