示例#1
0
def convolve_lnlam(R=10000, wlo=3e3, whi=1e4, wpad=20.0, **pars):
    """ Convolve to lower R.

    :param R:
        Desired resolution in lambda/delta_lambda_FWHM
    """
    wlim = wlo - wpad, whi + wpad
    fhires, whires = getflux_hires(**pars)
    good = (whires > wlim[0]) & (whires < wlim[1])

    R_sigma = R * sigma_to_fwhm
    dlnlam = 1.0 / (R_sigma *2.0)
    outwave = np.arange(np.log(wlo), np.log(whi), dlnlam)
    outwave = np.exp(outwave)
    # convert desired resolution to velocity and sigma instead of FWHM
    sigma_v = ckms / R / sigma_to_fwhm
    flux = smoothing.smooth_vel_fft(whires[good], fhires[good], outwave, sigma_v)
    return outwave, flux
示例#2
0
def convolve_lam(fwhm=1.0, wlo=4e3, whi=1e4, wpad=20.0,
                 rconv=sigma_to_fwhm, fast=False, **pars):
    """Convolve first to lower resolution (in terms of R) then do the
    wavelength dependent convolution to a constant sigma_lambda resolution.
    
    :param fwhm:
        Desired resolution delta_lambda_FWHM in AA
    """
    sigma = fwhm / sigma_to_fwhm
    wlim = wlo - wpad, whi + wpad

    # Read the spectrum
    ts = time.time()
    fhires, whires = getflux_hires(**pars)
    good = (whires > wlim[0]) & (whires < wlim[1])
    print('read in took {}s'.format(time.time() - ts))

    if fast:
        # ** This doesn't quite work ** - gives oversmoothed spectra
        # get most of the way by smoothing via fft
        ts = time.time()
        # Maximum lambda/sigma_lambda of the output spectrum, with a little padding
        Rint_sigma = whi / sigma * 1.1
        inres = Rint_sigma
        dlnlam = 1.0 / (Rint_sigma * 2.0)
        wmres = np.exp(np.arange(np.log(wlim[0]), np.log(wlim[1]), dlnlam))
        fmres = smoothing.smooth_vel_fft(whires[good], fhires[good], outwave=wmres,
                                         Rout=Rint_sigma, Rin=Rykc*rconv)
        print('intermediate took {}s'.format(time.time() - ts))
    else:
        good = (whires > wlim[0]) & (whires < wlim[1])
        wmres, fmres = whires[good], fhires[good]
        inres = Rykc*rconv

    # Do the final smoothing *without FFT* to try and capture wavelength
    # dependence of the resolution of the input spectrum
    ts = time.time()
    outwave = np.arange(wlo, whi, sigma / 2.0)
    flux = smoothing.smooth_wave(wmres, fmres, outwave, sigma, inres=inres,
                                 in_vel=True, nsigma=20)
    print('final took {}s'.format(time.time() - ts))

    return outwave, flux