Exemplo n.º 1
0
def initial_run(scalednames,traceflat,throughput=''):
    """Use **dohydra** to extract .ms multispec files from the input flat fields. 
    
    This is done so that we can stitch them back together in aperture space rather than pixel space. To save time we don't bother with any sort of wavelength solution or other garbage. Essentially all we do is aperture extraction, but in a way that will enable future **dohydra** runs on actual data.

    Parameters
    ----------

    scalednames : list of str
        The names of flat images that have had shutter correction applied
    
    traceflat : str
        Name of the flat to be used for tracing apertures
    
    throughput : str, optional
        Name of the image to use for throughput correction

    Returns
    -------
    
    outputnames : list of str
        The names of the extracted flat field multispec images
    
    outputscales : list of float 
        List of scaling applied to each flat by **dohydra**. This is returned so that it can be undone later.

    Notes
    -----
    **dohydra** automatically scales each extracted flat so that the mean is 1. This messes up our careful shutter correction/scaling so we need to keep track of these scales for future use.
    
    """
    
    oldlog = iraf.hydra.logfile
    print 'Doing initial flat aperture extraction...'
    idtable = os.path.basename(iraf.dohydra.apidtable)
    print '\tusing idtable {}'.format(idtable)
    outputnames = []
    outputscales = []
    for flat in scalednames:
        print '\trunning {}'.format(flat)
        iraf.hydra.logfile = '{}.log'.format(flat)
        try:
            iraf.dohydra('ffTmp.fits',
                         apref=traceflat,
                         flat=flat,
                         through=throughput,
                         readnoise=3.9,
                         gain=0.438,
                         fibers=109,
                         width=5,
                         minsep=1,
                         maxsep=10,
                         apidtable=APIDTABLE,
                         scatter=False,
                         fitflat=False,
                         clean=False,
                         dispcor=False,
                         savearc=False,
                         skyalign=False,
                         skysubt=False,
                         skyedit=False,
                         savesky=False,
                         splot=False,
                         redo=False,
                         update=False,
                         batch=False,
                         listonl=False,
                         Stdout=1)
        except iraf.IrafError:
            '''For some reason, if you run this from the shell
            (non-interactively) dohydra will always fail the first
            time when trying to copy the database file. If/when this
            happens we'll just return false so main() knows just to
            try it again.
            '''
            print 'F****d up, trying again'
            return False, False
        f = open('{}.log'.format(flat),'r')
        o = f.readlines()
        for dump in o:
            if 'bscale' in dump:
                scale = dump.split()[-1]
                outputscales.append(float(scale))
            if 'Create the normalized response' in dump:
                outname = '{}.fits'.format(dump.split()[-1])
                if outname not in outputnames:
                    outputnames.append('{}.fits'.format(dump.split()[-1]))
        os.remove('ffTmp.ms.fits')
        f.close()

    print "Extracted flats:"
    for out,scale in zip(outputnames,outputscales):
        print '\t{}  {}'.format(out,scale)
    iraf.hydra.logfile = oldlog
    return outputnames, outputscales
Exemplo n.º 2
0
def dohydra_err(errname):
    '''Propagate errors through **dohydra**

    Extract apertures, perform flat correction, and apply wavelength solution
    header values to the raw (.sig) error file.
    
    Errors are propagated assuming that the raw flat errors are minimal. This
    causes the full error term,

    .. math::
       \delta S' = \sqrt{(\delta F*S/F^2)^2 + (\delta S/F)^2 },

    to reduce to

    .. math::
       \delta S' = \delta S/F,

    where S is the extracted, .ms file, F is the flat and d represents errors
    on that particular image. The error on a particular aperture in the .ms
    file is simply

    .. math::
       \delta S = \sqrt{\sum_i(\delta I^2)},

    where :math:`\delta I` is the raw error (.sig) file and the sum is over all columns
    used in a fiber.

    Given the above expressions the final error (:math:`\delta S'`) is achieved by
    simply passing :math:`\delta I^2` and :math:`F^2` into dohydra and taking
    the square root of the result.

    '''
    #Save the OG flat so we can set it back once we're done with the squared
    #flat
    pd = iraf.dohydra.getParDict() 
    normal_flat = pd['flat'].get()

    msflat = find_msname(normal_flat)
    sq_errname, sq_flatname = create_tmps(errname,msflat)

    iraf.dohydra(sq_errname,
                 flat='tmp_sq{}'.format(normal_flat),
                 readnoise=3.9,
                 gain=0.438,
                 fibers=109,
                 width=5,
                 minsep=1,
                 maxsep=10,
                 apidtable=APIDTABLE,
                 scatter=False,
                 clean=False,
                 dispcor=True,
                 savearc=False,
                 skyalign=False,
                 skysubt=False,
                 skyedit=False,
                 savesky=False,
                 splot=False,
                 redo=False,
                 update=False,
                 batch=False,
                 listonl=False)
                 
    dohydra_output = '{}.ms.fits'.format(sq_errname.split('.fits')[0])
    final_image = dohydra_output.replace('tmp_sq','').\
        replace('sig.ms.fits','me.fits')
    pow_image(dohydra_output,final_image,0.5)

    #Set the flat back to whatever it was before
    pd['flat'].set(normal_flat)
    iraf.dohydra.saveParList()

    return final_image
Exemplo n.º 3
0
def dohydra_err(errname):
    '''Propagate errors through **dohydra**

    Extract apertures, perform flat correction, and apply wavelength solution
    header values to the raw (.sig) error file.
    
    Errors are propagated assuming that the raw flat errors are minimal. This
    causes the full error term,

    .. math::
       \delta S' = \sqrt{(\delta F*S/F^2)^2 + (\delta S/F)^2 },

    to reduce to

    .. math::
       \delta S' = \delta S/F,

    where S is the extracted, .ms file, F is the flat and d represents errors
    on that particular image. The error on a particular aperture in the .ms
    file is simply

    .. math::
       \delta S = \sqrt{\sum_i(\delta I^2)},

    where :math:`\delta I` is the raw error (.sig) file and the sum is over all columns
    used in a fiber.

    Given the above expressions the final error (:math:`\delta S'`) is achieved by
    simply passing :math:`\delta I^2` and :math:`F^2` into dohydra and taking
    the square root of the result.

    '''
    #Save the OG flat so we can set it back once we're done with the squared
    #flat
    pd = iraf.dohydra.getParDict()
    normal_flat = pd['flat'].get()

    msflat = find_msname(normal_flat)
    sq_errname, sq_flatname = create_tmps(errname, msflat)

    iraf.dohydra(sq_errname,
                 flat='tmp_sq{}'.format(normal_flat),
                 readnoise=3.9,
                 gain=0.438,
                 fibers=109,
                 width=5,
                 minsep=1,
                 maxsep=10,
                 apidtable=APIDTABLE,
                 scatter=False,
                 clean=False,
                 dispcor=True,
                 savearc=False,
                 skyalign=False,
                 skysubt=False,
                 skyedit=False,
                 savesky=False,
                 splot=False,
                 redo=False,
                 update=False,
                 batch=False,
                 listonl=False)

    dohydra_output = '{}.ms.fits'.format(sq_errname.split('.fits')[0])
    final_image = dohydra_output.replace('tmp_sq','').\
        replace('sig.ms.fits','me.fits')
    pow_image(dohydra_output, final_image, 0.5)

    #Set the flat back to whatever it was before
    pd['flat'].set(normal_flat)
    iraf.dohydra.saveParList()

    return final_image
Exemplo n.º 4
0
def initial_run(scalednames, traceflat, throughput=''):
    """Use **dohydra** to extract .ms multispec files from the input flat fields. 
    
    This is done so that we can stitch them back together in aperture space rather than pixel space. To save time we don't bother with any sort of wavelength solution or other garbage. Essentially all we do is aperture extraction, but in a way that will enable future **dohydra** runs on actual data.

    Parameters
    ----------

    scalednames : list of str
        The names of flat images that have had shutter correction applied
    
    traceflat : str
        Name of the flat to be used for tracing apertures
    
    throughput : str, optional
        Name of the image to use for throughput correction

    Returns
    -------
    
    outputnames : list of str
        The names of the extracted flat field multispec images
    
    outputscales : list of float 
        List of scaling applied to each flat by **dohydra**. This is returned so that it can be undone later.

    Notes
    -----
    **dohydra** automatically scales each extracted flat so that the mean is 1. This messes up our careful shutter correction/scaling so we need to keep track of these scales for future use.
    
    """

    oldlog = iraf.hydra.logfile
    print 'Doing initial flat aperture extraction...'
    idtable = os.path.basename(iraf.dohydra.apidtable)
    print '\tusing idtable {}'.format(idtable)
    outputnames = []
    outputscales = []
    for flat in scalednames:
        print '\trunning {}'.format(flat)
        iraf.hydra.logfile = '{}.log'.format(flat)
        try:
            iraf.dohydra('ffTmp.fits',
                         apref=traceflat,
                         flat=flat,
                         through=throughput,
                         readnoise=3.9,
                         gain=0.438,
                         fibers=109,
                         width=5,
                         minsep=1,
                         maxsep=10,
                         apidtable=APIDTABLE,
                         scatter=False,
                         fitflat=False,
                         clean=False,
                         dispcor=False,
                         savearc=False,
                         skyalign=False,
                         skysubt=False,
                         skyedit=False,
                         savesky=False,
                         splot=False,
                         redo=False,
                         update=False,
                         batch=False,
                         listonl=False,
                         Stdout=1)
        except iraf.IrafError:
            '''For some reason, if you run this from the shell
            (non-interactively) dohydra will always fail the first
            time when trying to copy the database file. If/when this
            happens we'll just return false so main() knows just to
            try it again.
            '''
            print 'F****d up, trying again'
            return False, False
        f = open('{}.log'.format(flat), 'r')
        o = f.readlines()
        for dump in o:
            if 'bscale' in dump:
                scale = dump.split()[-1]
                outputscales.append(float(scale))
            if 'Create the normalized response' in dump:
                outname = '{}.fits'.format(dump.split()[-1])
                if outname not in outputnames:
                    outputnames.append('{}.fits'.format(dump.split()[-1]))
        os.remove('ffTmp.ms.fits')
        f.close()

    print "Extracted flats:"
    for out, scale in zip(outputnames, outputscales):
        print '\t{}  {}'.format(out, scale)
    iraf.hydra.logfile = oldlog
    return outputnames, outputscales