Ejemplo n.º 1
0
def call_specrectify(file, i, object, calfile, file_out, verbose=0):

    if (verbose > 0):
        print "\n ** Calling SPECRECTIFY(" + file + ")\n\n"

    s = iraf.specrectify(images=file,
                         solfile=calfile,
                         outimages=file_out,
                         caltype='line',
                         function='polynomial',
                         order=3,
                         inttype='interp',
                         outpref='',
                         w1='None',
                         w2='None',
                         dw='None',
                         nw='None',
                         blank=0.0,
                         clobber=1,
                         logfile='salt_specrectify.log',
                         verbose=(verbose > 1))

    rcParams['figure.figsize'] = 20, 30
    hdulist = fits.open(file_out)
    image = hdulist['SCI'].data
    dy_spect_plot = 400  # How many rows vertically is the spectrum? ** Changes 2014 vs. 2015
    ny = image.shape[
        0]  # Look up the central row of the spectrum, and take +- dy/2 rows from that
    plt.imshow(log(image))
    plt.ylim((ny / 2 - dy_spect_plot / 2, ny / 2 + dy_spect_plot / 2))

    plt.title(file + ", " + object + ", " + ' RECT')
    plt.show()
    hdulist.close()
Ejemplo n.º 2
0
def rectify(ids=None, fs=None):
    iraf.cd('work')
    if ids is None:
        ids = np.array(glob('id2/arc*id2*.db'))
    if fs is None:
        fs = glob('srt/*mos*.fits')
    if len(ids) == 0:
        print "WARNING: No wavelength solutions for rectification."
        iraf.cd('..')
        return
    if len(fs) == 0:
        print "WARNING: No images for rectification."
        iraf.cd('..')
        return

    # Get the grating angles of the solution files
    idgas = []
    for i, thisid in enumerate(ids):
        f = open(thisid)
        idlines = np.array(f.readlines(), dtype=str)
        f.close()
        idgaline = idlines[np.char.startswith(idlines, '#graang')][0]
        idgas.append(float(idgaline.split('=')[1]))

    ims, gas = get_scis_and_arcs(fs)
    if not os.path.exists('rec'):
        os.mkdir('rec')
    for i, f in enumerate(ims):
        fname = f.split('/')[1]
        typestr = fname[:3]
        ga, imgnum = gas[i], fname[-9:-5]

        outfile = 'rec/' + typestr + '%05.2frec' % (ga) + imgnum + '.fits'
        iraf.unlearn(iraf.specrectify)
        iraf.flpr()
	print('_____idgas_____')
	print (np.array(idgas))
	print('_____ga_____')
	print (ga)
        idfile = ids[np.array(idgas) == ga][0]
        iraf.specrectify(images=f, outimages=outfile, solfile=idfile,
                         outpref='', function='legendre', order=3,
                         inttype='interp', conserve='yes', clobber='yes',
                         verbose='yes')

        # Update the BPM to mask any blank regions
        h = pyfits.open(outfile, 'update')
        # Cover the chip gaps. The background task etc do better if the chip
        # gaps are straight
        # To deal with this we just throw away the min and max of each side of
        # the curved chip gap
        chipgaps = get_chipgaps(h)
        print(" -- chipgaps --")
        print(chipgaps)

        # Chip 1
        h[2].data[:, chipgaps[0][0]:chipgaps[0][1]] = 1
        # Chip 2
        h[2].data[:, chipgaps[1][0]:chipgaps[1][1]] = 1
        # edge of chip 3
        h[2].data[:, chipgaps[2][0]:chipgaps[2][1]] = 1
        # Cover the other blank regions
        h[2].data[[h[1].data == 0]] = 1

        # Set all of the data to zero in the BPM
        h[1].data[h[2].data == 1] = 0.0
        h.flush()
        h.close()
    iraf.cd('..')
Ejemplo n.º 3
0
##########

    if (object[i] in ["Pluto", "HD 146233", "ARC"]) & (DO_SPECRECTIFY):
        e = os.path.exists(files_cr_rect[i])
        print "SPECRECTIFY: File " + files_cr_rect[i] + " exists: " + repr(e)
        if (not e) | (DO_FORCE_CAL_SINGLE):
            print "\n ** Calling SPECRECTIFY(" + files[i] + "), i = " + repr(
                i) + ", object = " + object[i] + "\n\n"
            s = iraf.specrectify(images=files_cr[i],
                                 solfile=calfile,
                                 outimages=files_cr_rect[i],
                                 caltype='line',
                                 function='polynomial',
                                 order=3,
                                 inttype='interp',
                                 outpref='',
                                 w1='None',
                                 w2='None',
                                 dw='None',
                                 nw='None',
                                 blank=0.0,
                                 clobber=1,
                                 logfile='salt_specrectify.log',
                                 verbose=1)

        rcParams['figure.figsize'] = 20, 30
        hdulist = fits.open(files_cr_rect[i])
        image = hdulist['SCI'].data
        dy_spect_plot = 400  # How many rows vertically is the spectrum?
        ny = image.shape[
            0]  # Look up the central row of the spectrum, and take +- dy/2 rows from that
        plt.imshow(log(image))
Ejemplo n.º 4
0
def rectify(ids=None, fs=None):
    iraf.cd('work')
    if ids is None:
        ids = np.array(glob('id2/arc*id2*.db'))
    if fs is None:
        fs = glob('mos/*mos*.fits')
    if len(ids) == 0:
        print "WARNING: No wavelength solutions for rectification."
        iraf.cd('..')
        return
    if len(fs) == 0:
        print "WARNING: No images for rectification."
        iraf.cd('..')
        return

    # Get the grating angles of the solution files
    idgas = []
    for i, thisid in enumerate(ids):
        f = open(thisid)
        idlines = np.array(f.readlines(), dtype=str)
        f.close()
        idgaline = idlines[np.char.startswith(idlines, '#graang')][0]
        idgas.append(float(idgaline.split('=')[1]))

    ims, gas = get_scis_and_arcs(fs)
    if not os.path.exists('rec'):
        os.mkdir('rec')
    for i, f in enumerate(ims):
        fname = f.split('/')[1]
        typestr = fname[:3]
        ga, imgnum = gas[i], fname[-9:-5]

        outfile = 'rec/' + typestr + '%05.2frec' % (ga) + imgnum + '.fits'
        iraf.unlearn(iraf.specrectify)
        iraf.flpr()
        idfile = ids[np.array(idgas) == ga][0]
        iraf.specrectify(images=f, outimages=outfile, solfile=idfile,
                         outpref='', function='legendre', order=3,
                         inttype='interp', conserve='yes', clobber='yes',
                         verbose='yes')

        # Update the BPM to mask any blank regions
        h = pyfits.open(outfile, 'update')
        # Cover the chip gaps. The background task etc do better if the chip
        # gaps are straight
        # To deal with this we just throw away the min and max of each side of
        # the curved chip gap
        chipgaps = get_chipgaps(h)

        # Chip 1
        h[2].data[:, chipgaps[0][0]:chipgaps[0][1]] = 1
        # Chip 2
        h[2].data[:, chipgaps[1][0]:chipgaps[1][1]] = 1
        # edge of chip 3
        h[2].data[:, chipgaps[2][0]:chipgaps[2][1]] = 1
        # Cover the other blank regions
        h[2].data[[h[1].data == 0]] = 1

        # Set all of the data to zero in the BPM
        h[1].data[h[2].data == 1] = 0.0
        h.flush()
        h.close()
    iraf.cd('..')