Example #1
0
def buildMaskImage(rootname, bitvalue, extname='DQ', extver=1):
    """ Builds mask image from rootname's DQ array 
        If there is no valid 'DQ' array in image, then return
        an empty string.
    """
    # If no bitvalue is set, assume no mask is desired
    if bitvalue == None:
        return None

    # build output name
    _indx = string.find(rootname, '.fits')
    if _indx > 0:
        maskname = rootname[:_indx] + '_inmask' + repr(extver) + '.fits'
        whtname = rootname[:_indx] + '_wtmask' + repr(extver) + '.fits'  #WZ
    else:
        maskname = rootname + '_inmask' + repr(extver) + '.fits'
        whtname = rootname + '_wtmask' + repr(extver) + '.fits'  #WZ
    # If an old version of the maskfile was present, remove it and rebuild it.
    if fileutil.findFile(maskname) == yes:
        os.remove(maskname)
    if fileutil.findFile(whtname) == yes:  #WZ
        os.remove(whtname)

    # Open input file with DQ array
    fdq = pyfits.open(rootname)
    try:
        # Read in DQ array
        dqarr = fdq[extname, extver].data

        # Build mask array from DQ array
        maskarr = buildMask(dqarr, bitvalue)

        #Write out the mask file as simple FITS file
        fmask = pyfits.open(maskname, 'append')
        maskhdu = pyfits.PrimaryHDU(data=maskarr)
        fmask.append(maskhdu)

        #Close files
        fmask.close()
        del fmask
    except:
        return None

    fdq.close()
    del fdq

    # Return the name of the mask image written out
    return maskname
Example #2
0
 def verifyShiftFile(self):
     """
     Verifies that reference file exists.
     """
     if self['refimage'] and fu.findFile(self['refimage']):
         return True
     else: return False
Example #3
0
def buildShadowMaskImage(rootname, detnum, replace=no):
    """ Builds mask image from WFPC2 shadow calibrations.
      detnum - string value for 'DETECTOR' detector  
    """
    # insure detnum is a string
    if not isinstance(detnum, types.StringType):
        detnum = repr(detnum)

    _funcroot = '_func_Shadow_WF'
    # build template shadow mask's filename
    _mask = 'wfpc2_inmask' + detnum + '.fits'

    if rootname != None:
        # build output name by stripping off old extension from rootname...
        _name = drutil.buildNewRootname(rootname)
        #print 'found rootname of ',_name
        # ... now add our own syntax and extension to the output name.
        _indx = string.find(_name, '.')
        if _indx > 0:
            maskname = _name[:_indx] + '_inmask' + detnum + '.fits'
        else:
            maskname = _name + '_inmask' + detnum + '.fits'
    else:
        maskname = None
    # Check to see if file exists...
    if fileutil.findFile(_mask) == no or replace:
        # If not, create the file.
        # This takes a long time to run, so it should be done
        # only when absolutely necessary...
        try:
            _funcx = _funcroot + detnum + 'x'
            _funcy = _funcroot + detnum + 'y'

            _xarr = clip(fromfunction(eval(_funcx), (800, 800)), 0.0,
                         1.0).astype(int16)
            _yarr = clip(fromfunction(eval(_funcy), (800, 800)), 0.0,
                         1.0).astype(int16)
            maskarr = _xarr * _yarr

            #Write out the mask file as simple FITS file
            fmask = pyfits.open(_mask, 'append')
            maskhdu = pyfits.PrimaryHDU(data=maskarr)
            fmask.append(maskhdu)

            #Close files
            fmask.close()
            del fmask
        except:
            return None

    # Now, copy template mask file to output file, if necessary
    if maskname != None:
        fileutil.copyFile(_mask, maskname, replace=no)
    # Return the name of the mask image written out
    return maskname
Example #4
0
    def __init__(self, inlist=None, output=None, shiftfile=None):
        """
        Parameters
        ===========
        `inlist`: a list
                  a python list of filenames
        `output`  a string
                  a user specified output name or 'final'
        `shiftfile`: a string
                  a name of a shift file, if given, the association table will be
                  updated with the values in the shift file

        """

        if output == None:
            if len(inlist) == 1:
                self.output = fu.buildNewRootname(inlist[0])
            else:
                self.output = 'final'
        else:
            self.output = fu.buildNewRootname(output)
            # Ensure that output name does not already contain '_drz'
            _indx = self.output.find('_drz')
            if _indx > 0:
                self.output = self.output[:_indx]

        self.order = []
        if inlist != None:
            for fn in inlist:
                if fu.findFile(fu.buildRootname(fn)):
                    self.order.append(fu.buildNewRootname(fn))
                else:
                    # This may mean corrupted asn table in which a file is listed as present
                    # when it is missing.
                    raise IOError,  'File %s not found.\n' %fn
        dict.__init__(self, output=self.output, order=[], members={})
        if inlist != None:
            self.input = [fu.buildRootname(f) for f in inlist]
        self.shiftfile = shiftfile