Example #1
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)
Example #2
0
 def __init__(self, s1, s2, x):
     self.sci = s1 / np.median(s1)
     self.rawt = s2
     self.x = x
     self.tcc, self.shift = cc.ccshift(s1, self.rawt, self.x, quiet=False)
     self.tsr, self.c = rescale(s1, self.tcc)
     self.tcor = self.sci / self.tsr
Example #3
0
def linebyline(x, tcspec, fspec):
    """Calculate radial velocity shift for groups of lines individually"""
    lines = defidx(x)
    # wid = 0.0010
    slbl = []
    for l in lines:
        slbli, tmp = cc.crossc(fspec, tcspec, i1=l[0], i2=l[-1])
        slbl = np.append(slbl, slbli * -1)
    return slbl