def buildEmptyDRZ(input, output):
    """
    Create an empty DRZ file.

    This module creates an empty DRZ file in a valid FITS format so that the HST
    pipeline can handle the Multidrizzle zero expossure time exception
    where all data has been excluded from processing.

    Parameters
    ----------
    input : str
        filename of the initial input to process_input
    output : str
        filename of the default empty _drz.fits file to be generated

    """

    # Identify the first input image
    inputfile = parseinput.parseinput(input)[0]
    if not inputfile:
        print('\n******* ERROR *******', file=sys.stderr)
        print(
              'No input file found!  Check specification of parameter '
              '"input". ', file=sys.stderr)
        print('Quitting...',  file=sys.stderr)
        print('******* ***** *******\n',  file=sys.stderr)
        return # raise IOError, "No input file found!"

    # Set up output file here...
    if output is None:
        if len(input) == 1:
            oname = fileutil.buildNewRootname(input[0])
        else:
            oname = 'final'
        output = fileutil.buildNewRootname(oname, extn='_drz.fits')
    else:
        if 'drz' not in output:
            output = fileutil.buildNewRootname(output, extn='_drz.fits')

    log.info('Setting up output name: %s' % output)

    # Open the first image (of the excludedFileList?) to use as a template to build
    # the DRZ file.
    try :
        log.info('Building empty DRZ file from %s' % inputfile[0])
        img = fits.open(inputfile[0], memmap=False)
    except:
        raise IOError('Unable to open file %s \n' % inputfile)

    # Create the fitsobject
    fitsobj = fits.HDUList()
    # Copy the primary header
    hdu = img[0].copy()
    fitsobj.append(hdu)

    # Modify the 'NEXTEND' keyword of the primary header to 3 for the
    #'sci, wht, and ctx' extensions of the newly created file.
    fitsobj[0].header['NEXTEND'] = 3

    # Create the 'SCI' extension
    hdu = fits.ImageHDU(header=img['sci', 1].header.copy())
    hdu.header['EXTNAME'] = 'SCI'
    fitsobj.append(hdu)

    # Create the 'WHT' extension
    hdu = fits.ImageHDU(header=img['sci', 1].header.copy())
    hdu.header['EXTNAME'] = 'WHT'
    fitsobj.append(hdu)

    # Create the 'CTX' extension
    hdu = fits.ImageHDU(header=img['sci', 1].header.copy())
    hdu.header['EXTNAME'] = 'CTX'
    fitsobj.append(hdu)

    # Add HISTORY comments explaining the creation of this file.
    fitsobj[0].header.add_history("** AstroDrizzle has created this empty "
                                  "DRZ product because**")
    fitsobj[0].header.add_history("** all input images were excluded from "
                                  "processing.**")


    # Change the filename in the primary header to reflect the name of the output
    # filename.
    fitsobj[0].header['FILENAME'] = str(output)  # +"_drz.fits"

    # Change the ROOTNAME keyword to the ROOTNAME of the output PRODUCT
    fitsobj[0].header['ROOTNAME'] = str(output.split('_drz.fits')[0])
    # Modify the ASN_MTYP keyword to contain "PROD-DTH" so it can be properly
    # ingested into the archive catalog.

    # stis has this keyword in the [1] header, so I am directing the code
    #t o first look in the primary, then the 1
    try:
        fitsobj[0].header['ASN_MTYP'] = 'PROD-DTH'
    except:
        fitsobj[1].header['ASN_MTYP'] = 'PROD-DTH'

    # If the file is already on disk delete it and replace it with the
    # new file
    dirfiles = os.listdir(os.curdir)
    if dirfiles.count(output) > 0:
        os.remove(output)
        log.info("       Replacing %s..." % output)

    # Write out the empty DRZ file
    fitsobj.writeto(output)

    print(textutil.textbox(
        'ERROR:\nAstroDrizzle has created an empty DRZ product because all '
        'input images were excluded from processing or a user requested the '
        'program to stop.') + '\n', file=sys.stderr)

    return
def buildEmptyDRZ ( input , output ) : inputfile = parseinput . parseinput ( input ) [ 0 ] if not inputfile : print ( '\n******* ERROR *******' , file = sys . stderr ) print ( 'No input file found!  Check specification of parameter ' '"input". ' , file = sys . stderr ) print ( 'Quitting...' , file = sys . stderr ) print ( '******* ***** *******\n' , file = sys . stderr ) return if output is None : if len ( input ) == 1 : oname = fileutil . buildNewRootname ( input [ 0 ] ) else : oname = 'final' output = fileutil . buildNewRootname ( oname , extn = '_drz.fits' ) else : if 'drz' not in output : output = fileutil . buildNewRootname ( output , extn = '_drz.fits' ) log . info ( 'Setting up output name: %s' % output ) try : log . info ( 'Building empty DRZ file from %s' % inputfile [ 0 ] ) img = fits . open ( inputfile [ 0 ] , memmap = False ) except : raise IOError ( 'Unable to open file %s \n' % inputfile ) fitsobj = fits . HDUList ( ) hdu = img [ 0 ] . copy ( ) fitsobj . append ( hdu ) fitsobj [ 0 ] . header [ 'NEXTEND' ] = 3 hdu = fits . ImageHDU ( header = img [ 'sci' , 1 ] . header . copy ( ) ) hdu . header [ 'EXTNAME' ] = 'SCI' fitsobj . append ( hdu ) hdu = fits . ImageHDU ( header = img [ 'sci' , 1 ] . header . copy ( ) ) hdu . header [ 'EXTNAME' ] = 'WHT' fitsobj . append ( hdu ) hdu = fits . ImageHDU ( header = img [ 'sci' , 1 ] . header . copy ( ) ) hdu . header [ 'EXTNAME' ] = 'CTX' fitsobj . append ( hdu ) fitsobj [ 0 ] . header . add_history ( "** AstroDrizzle has created this empty " "DRZ product because**" ) fitsobj [ 0 ] . header . add_history ( "** all input images were excluded from " "processing.**" ) fitsobj [ 0 ] . header [ 'FILENAME' ] = str ( output ) fitsobj [ 0 ] . header [ 'ROOTNAME' ] = str ( output . split ( '_drz.fits' ) [ 0 ] ) try : fitsobj [ 0 ] . header [ 'ASN_MTYP' ] = 'PROD-DTH' except : fitsobj [ 1 ] . header [ 'ASN_MTYP' ] = 'PROD-DTH' dirfiles = os . listdir ( os . curdir ) if dirfiles . count ( output ) > 0 : os . remove ( output ) log . info ( "       Replacing %s..." % output ) fitsobj . writeto ( output ) print ( textutil . textbox ( 'ERROR:\nAstroDrizzle has created an empty DRZ product because all ' 'input images were excluded from processing or a user requested the ' 'program to stop.' ) + '\n' , file = sys . stderr ) return
Create an empty DRZ file.

    This module creates an empty DRZ file in a valid FITS format so that the HST
    pipeline can handle the Multidrizzle zero expossure time exception
    where all data has been excluded from processing.

    Parameters
    ----------
    input : str
        filename of the initial input to process_input
    output : str
        filename of the default empty _drz.fits file to be generated