def plot_spec(ccd1,
              ccd2,
              ccd3,
              ccd4,
              fuv,
              offset,
              ax_ccd,
              ax_fuv,
              fuv_offset=None):
    if not fuv_offset:
        fuv_offset = offset

    tbdata1 = pyfits.getdata(ccd1, 1)
    print tbdata1.names
    wl1 = tbdata1['wavelength'].ravel()
    net1 = tbdata1['net'].ravel()
    net1_4000 = degrader(wl1, net1, 7000., 4000., quick=5)
    tbdata2 = pyfits.getdata(ccd2, 1)
    wl2 = tbdata2['wavelength'].ravel()
    net2 = tbdata2['net'].ravel()
    net2_4000 = degrader(wl2, net2, 7000., 4000., quick=5)
    tbdata3 = pyfits.getdata(ccd3, 1)
    wl3 = tbdata3['wavelength'].ravel()
    net3 = tbdata3['net'].ravel()
    net3_4000 = degrader(wl3, net3, 7000., 4000., quick=5)
    tbdata4 = pyfits.getdata(ccd4, 1)
    wl4 = tbdata4['wavelength'].ravel()
    net4 = tbdata4['net'].ravel()
    net4_4000 = degrader(wl4, net4, 7000., 4000., quick=5)
    tbdata5 = pyfits.getdata(fuv, 1)
    wl5 = tbdata5['wavelength'].ravel()
    net5 = tbdata5['flux'].ravel()

    ax_fuv.plot(wl5, net5 + fuv_offset, c='k')
    ax_fuv.set_xlim(1150, 1700)
    ax_fuv.set_ylim(-0.1, 2.3 + offset)

    ax_ccd.plot(wl1, net1_4000 + offset, c='k')
    ax_ccd.plot(wl2, net2_4000 + offset, c='b')
    ax_ccd.plot(wl3, net3_4000 + offset, c='k')
    ax_ccd.plot(wl4, net4_4000 + offset, c='b')
    ax_ccd.set_xlim(3900, 4750)
    ax_ccd.set_ylim(-0.1, 2.3 + offset)
    return ax_ccd, ax_fuv
Ejemplo n.º 2
0
def rv(fsci, ftell, rsgmod, xrsg, atspec, hcorr):
    """
        Calculate RV for a science spectrum extracted from brighest pixel
        Initial guess comes from a cross-correlation for the entire region
        This is then improved upon by using specific lines and regions within
        the 1.17-1.22um region.
    """
    scic = SciComb(pyfits.open(fsci))
    # For cross-correlation to rest use telluric index:
    it = np.where((scic.x > 1.12) & (scic.x < 1.15))[0]
    xtell = scic.x[it]
    scixtell = scic.bspec[it]
    atxtell = atspec[it]
    scixtell_, sr = cc.ccshift(atxtell, scixtell, xtell, quiet=False)

    # Implement shift-to-rest (sr) in diagnostic region
    xdiag = scic.x[scic.roi]
    scidiag = scic.bspec[scic.roi]
    atdiag = atspec[scic.roi]
    print('[INFO] Shift science spectrum to rest using telluric features:')
    scirest, s2 = cc.ccshift(atdiag, scidiag, xdiag, shift1=sr, quiet=False)

    # Telluric correct:
    print('[INFO] Telluric correct data once shifted onto rest wavelength:')
    tellcube = TellCube(ftell)
    tspec = tellcube.data[scic.ifu - 1].data
    scitc = TellCor(scirest, tspec[scic.roi], scic.x[scic.roi])

    # Prepare fake spectrum:
    # Match sampling between fake spectrum and observations
    # Degrade & resample:
    fsam = resam(xrsg, rsgmod, scic.x)
    fdeg = degrader(scic.x, fsam, 10000, 3000)
    fdiag = fdeg[scic.roi]
    print('[INFO] Calculate RV shift:')
    scirv, rvs = cc.ccshift(fdiag, scitc.tcor, xdiag, quiet=False, width=20)
    rvkms = lambda shift, delta, lam: shift * delta * C / lam
    rvi = rvkms(rvs * -1, scic.delt, 1.2)
    rvall = rvcorr(rvi, hcorr)
    print('[INFO] RV derived using the whole region: {}'.format(rvall))
    # Calculate errors:
    slbl = linebyline(xdiag, scirv, fdiag) + rvs * -1
    slbl = slbl[np.where(slbl != 0.0)]
    rvlbl = rvkms(slbl, scic.delt, 1.2)
    avrv = rvcorr(np.mean(rvlbl), hcorr)
    erv = np.std(rvlbl) / np.sqrt(np.shape(rvlbl)[0])
    print('[INFO] Average RV line by line: {} +/- {}'.format(avrv, erv))
    print('[INFO] RVs: {}'.format(rvcorr(rvlbl, hcorr)))
    return scic, scitc, avrv, erv, sr, rvcorr(rvlbl, hcorr)
Ejemplo n.º 3
0
def plot_spec(ccd1, ccd2, ccd3, ccd4, fuv, offset, ax_ccd, ax_fuv, fuv_offset = None):
    if not fuv_offset:
        fuv_offset = offset

    tbdata1 = pyfits.getdata(ccd1, 1)
    print tbdata1.names
    wl1 = tbdata1['wavelength'].ravel()
    net1 = tbdata1['net'].ravel()
    net1_4000 = degrader(wl1, net1, 7000., 4000., quick = 5)
    tbdata2 = pyfits.getdata(ccd2, 1)
    wl2 = tbdata2['wavelength'].ravel()
    net2 = tbdata2['net'].ravel()
    net2_4000 = degrader(wl2, net2,7000., 4000., quick = 5)
    tbdata3 = pyfits.getdata(ccd3, 1)
    wl3 = tbdata3['wavelength'].ravel()
    net3 = tbdata3['net'].ravel()
    net3_4000 = degrader(wl3, net3, 7000., 4000., quick = 5)
    tbdata4 = pyfits.getdata(ccd4, 1)
    wl4 = tbdata4['wavelength'].ravel()
    net4 = tbdata4['net'].ravel()
    net4_4000 = degrader(wl4, net4, 7000., 4000., quick = 5)
    tbdata5 = pyfits.getdata(fuv, 1)
    wl5 = tbdata5['wavelength'].ravel()
    net5 = tbdata5['flux'].ravel()
    
    ax_fuv.plot(wl5, net5+fuv_offset, c = 'k')
    ax_fuv.set_xlim(1150, 1700)
    ax_fuv.set_ylim(-0.1, 2.3+offset)

    ax_ccd.plot(wl1, net1_4000+offset, c = 'k')
    ax_ccd.plot(wl2, net2_4000+offset, c = 'b')
    ax_ccd.plot(wl3, net3_4000+offset, c = 'k')
    ax_ccd.plot(wl4, net4_4000+offset, c = 'b')
    ax_ccd.set_xlim(3900, 4750)
    ax_ccd.set_ylim(-0.1, 2.3+offset)
    return ax_ccd, ax_fuv
Ejemplo n.º 4
0
def wraprv(scipath, ftell, rsgmod, xrsg):
    """
        Wrap the rv.rv routine by giving it a list of spectra

        Usage:

        rv.wraprv('path/to/sci_combined/files', '/path/telluric_YJYJYJ.fits')
    """
    hcorr = raw_input('[INFO] Please enter heliocentric corr. for target:\n')
    hcorr = float(hcorr)
    scifiles = sorted(glob.glob(scipath + '*sci_combined_*'))

    # Avoid repeating this procedure by assuming all spectra have same x-axis
    tmpsci = SciComb(pyfits.open(scifiles[0]))
    print('[INFO] Match sampling and degrade atmos. spec. to match observed')
    atssam = resam(xat_hres, atspec_hres, tmpsci.x)
    # Clean up edges -- taken from N6822_Vrad.v2.py -- is this necesssary?
    atssam[np.where(atssam < 0.0)[0]] = 0
    print('[INFO] Degrade atmos spec to match science:')
    # From ESO's ISAAC decommissioned webpages R = 40000
    atspec = degrader(tmpsci.x, atssam, 40000, 3000)

    rvall = []
    rvstd = []
    name = []
    tcspec = []
    strest = []
    rvwhole = []

    for scifile in scifiles:
        print('[INFO] Use rv.rv for ', scifile)
        namei, tcspeci, rvi, erri, sr, rvwi = rv(scifile, ftell, rsgmod, xrsg,
                                                 atspec, hcorr)
        rvall = np.append(rvall, rvi)
        rvstd = np.append(rvstd, erri)
        name = np.append(name, namei)
        tcspec = np.append(tcspec, tcspeci)
        strest = np.append(strest, sr)
        rvwhole = np.append(rvwhole, rvwi)
    print('--' * 30)
    print('[INFO] Average RV for the sample: {} +/- {}'.format(
        rvall.mean(), rvall.std()))
    print('--' * 30)
    return name, tcspec, rvall, rvstd, strest, rvwhole