Exemplo n.º 1
0
def ArcReduce(files, band, aptops=None, apbottoms=None, debug=False):
    """
    Reduce the arc file: dark-correct, flat-correct, extract,
    and fit the wavelength solution

    :param files: The files structure
    :param band: Either H or K
    :param aptops: The coefficients for the tops of the apertures
    :param apbottoms: The coefficients for the bottoms of the apertures
    :param debug:
    :return:
    """

    # Read in the arc files
    imgsA, hdrsA = utilities.readechellogram(files.Arcs["ON"])
    imgsB, hdrsB = utilities.readechellogram(files.Arcs["OFF"])

    #Bad pixel corrections
    imgsA, hdrsA = utilities.barebadpixcor(imgsA, band, headers=hdrsA)
    imgsB, hdrsB = utilities.barebadpixcor(imgsB, band, headers=hdrsB)

    #Combine
    on, hdr_on = utilities.barecombine(imgsA, method="median", hdr=hdrsA[0])
    off, hdr_off = utilities.barecombine(imgsB, method="median", hdr=hdrsB[0])

    #Subtract on from off
    arc, hdr = utilities.baresubtract(on, off, hdr=hdr_on)

    #Divide by the flat
    flat, fhdr = PL_Display.readfits("%s/FLAT.fits" %files.WorkingDirectory)
    arc, hdr = utilities.flatcorrect([arc], flat, headers=[hdr])
    arc = arc[0]
    hdr = hdr[0]

    #Save the file
    print "Saving master arc to %s/ARC.fits" %files.WorkingDirectory
    PL_Display.savefits("%s/ARC.fits" %files.WorkingDirectory, arc, hdr)

    #Extract the apertures using the apertures defined by the flat
    if aptops is None or apbottoms is None:
        aptops, apbottoms = TraceApertures(flat,
                                           fhdr,
                                           band=band,
                                           target_path="%s/aperture_mapping/" %files.WorkingDirectory,
                                           debug=debug)
    spectra, ypos = ExtractFromApertures(arc, hdr, aptops, apbottoms)

    #Fit the Arc spectrum to determine the 2d wavelength calibration
    wave_coeffs = FitDispersion(spectra,
                                ypos,
                                band=band,
                                outpath="%s/aperture_mapping/" %files.WorkingDirectory)






    return None
Exemplo n.º 2
0
def FlatReduce(files, band, debug=False):
    """
    Function to reduce the flat frames.
    """
    """
    #Read in the file
    imgsA, hdrsA = utilities.readechellogram(files.Flats["ON"])
    imgsB, hdrsB = utilities.readechellogram(files.Flats["OFF"])

    #Bad pixel corrections
    imgsA, hdrsA = utilities.barebadpixcor(imgsA, band, headers=hdrsA)
    imgsB, hdrsB = utilities.barebadpixcor(imgsB, band, headers=hdrsB)

    #Combine
    on, hdr_on = utilities.barecombine(imgsA, method="median", hdr=hdrsA[0])
    off, hdr_off = utilities.barecombine(imgsB, method="median", hdr=hdrsB[0])

    #Subtract on from off
    flat, hdr = utilities.baresubtract(on, off, hdr=hdr_on)

    # Do cosmic ray correction
    flat = PL_Display.ip.cosmicrays(flat, threshold=2000, flux_ratio=0.2, wbox=3)

    # Normalize
    flat, hdr = utilities.barenormalize(flat, hdr, band=band)

    #Save the file
    print "Saving master flat to %s/FLAT.fits" %files.WorkingDirectory
    PL_Display.savefits("%s/FLAT.fits" %files.WorkingDirectory, flat, hdr)

    """
    flat, hdr = PL_Display.readfits("%s/FLAT.fits" %files.WorkingDirectory)

    #Find the apertures
    startcol = 1024
    medsize = 20
    icol = np.median(flat[:,(startcol-medsize/2):(startcol+medsize/2)], axis=1)
    apertures, tops, bottoms = FindApertures(icol)
    #sys.exit()

    #Trace the apertures
    ap_coeffs1, ap_coeffs2 = TraceApertures(flat,
                                            hdr,
                                            band=band,
                                            target_path="%s/aperture_mapping/" %files.WorkingDirectory,
                                            debug=debug)

    return ap_coeffs1, ap_coeffs2