当前位置: 首页>>代码示例>>Python>>正文


Python AbsLine.generate_voigt方法代码示例

本文整理汇总了Python中linetools.spectralline.AbsLine.generate_voigt方法的典型用法代码示例。如果您正苦于以下问题:Python AbsLine.generate_voigt方法的具体用法?Python AbsLine.generate_voigt怎么用?Python AbsLine.generate_voigt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在linetools.spectralline.AbsLine的用法示例。


在下文中一共展示了AbsLine.generate_voigt方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_voigt_model

# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import generate_voigt [as 别名]
def test_voigt_model():
    from astropy.modeling import fitting
    # Wavelength array
    wave = np.linspace(3644, 3650, 100)*u.AA
    # HI line
    abslin = AbsLine(1215.670*u.AA, z=2.)
    abslin.attrib['N'] = 10**14./u.cm**2
    abslin.attrib['b'] = 25.*u.km/u.s
    # Voigt
    vmodel = abslin.generate_voigt(wave=wave)
    vmodel.sig = 0.1
    # Voigt fit
    abslin.analy['spec'] = vmodel
    abslin.limits.set([-100.,100]*u.km/u.s)
    abslin.measure_aodm(normalize=False)  # Sets analysis pixels
    fitvoigt = lav.single_voigt_model(logN=np.log10(abslin.attrib['N'].value),
        b=abslin.attrib['b'].value, z=2., wrest=abslin.wrest.value,
        gamma=abslin.data['gamma'].value,
        f=abslin.data['f'], fwhm=3.)
    # Restrict parameter space
    fitvoigt.logN.min = 12.
    fitvoigt.b.min = 10.
    fitvoigt.z.min = 2. + -100. * (1 + 2.) / c_kms
    fitvoigt.z.max = 2. + 100 * (1 + 2.) / c_kms

    # Fit
    fitter = fitting.LevMarLSQFitter()
    parm = fitter(fitvoigt,vmodel.wavelength[abslin.analy['pix']].value,
                  vmodel.flux[abslin.analy['pix']].value)
    assert np.abs(parm.logN.value-np.log10(abslin.attrib['N'].value)) < 0.1
开发者ID:linetools,项目名称:linetools,代码行数:32,代码来源:test_voigt.py

示例2: plot_absline

# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import generate_voigt [as 别名]
def plot_absline(iinp,logN,b, show=True):
    """Plot an absorption line with N,b properties

    Parameters
    ----------
    iinp : float or str
      Rest wavelength (Ang) or name of transition (e.g. CIV1548)
    logN : float
      Log10 column
    b : float
      Doppler parameter (km/s)
    show : bool
      Whether to display the plot (set False for running
      tests). Default True.
    """
    import numpy as np
    from linetools.spectralline import AbsLine
    from astropy import units as u

    # Search for the closest absline
    if isinstance(iinp,basestring):
        aline = AbsLine(iinp, closest=True)
    else:
        aline = AbsLine(iinp*u.AA, closest=True)
    wrest = aline.wrest.value

    # Generate a fake wavelength array near the line
    wvoff = 50. # Ang
    dwv = wrest/100000. # Ang (echelle)
    wave = np.arange(wrest-wvoff, wrest+wvoff, dwv)

    # Generate spectrum with voigt
    aline.attrib['N'] = 10**logN * u.cm**-2
    aline.attrib['b'] = b * u.km/u.s
    xspec = aline.generate_voigt(wave=wave*u.AA)
    # get the plotting limits
    # remove first and last pixels
    fl = xspec.flux.value[1:-2]
    ind = np.flatnonzero(fl < 1 - 0.1 * (1 - np.min(fl)))
    ind += 1
    wmin = xspec.wavelength[max(0, ind[0] - 10)]
    wmax = xspec.wavelength[min(len(xspec.flux) - 1,  ind[-1] + 10)]
    #import pdb; pdb.set_trace()
    xspec.constant_sig(0.1) # S/N = 10 per pix

    # Calculate EW
    aline.analy['spec'] = xspec
    aline.analy['wvlim'] = np.array([wrest-15., wrest+15])*u.AA
    aline.measure_ew()
    print(aline)
    print('EW = {:g}'.format(aline.attrib['EW']))

    # Plot
    xspec.plot(xlim=(wmin.to(u.AA).value, wmax.to(u.AA).value), show=show)
开发者ID:banados,项目名称:linetools,代码行数:56,代码来源:lt_absline.py

示例3: test_voigt_sngl_line

# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import generate_voigt [as 别名]
def test_voigt_sngl_line():
    # Wavelength array
    wave = np.linspace(3644, 3650, 100)*u.AA
    imn = np.argmin(np.abs(wave.value-3647))
    # HI line
    abslin = AbsLine(1215.670*u.AA, z=2.)
    abslin.attrib['N'] = 10**14./u.cm**2
    abslin.attrib['b'] = 25.*u.km/u.s
    # Voigt
    vmodel = abslin.generate_voigt(wave=wave)
    np.testing.assert_allclose(vmodel.flux[imn].value,0.05145500775919881)
开发者ID:jnburchett,项目名称:linetools,代码行数:13,代码来源:test_voigt.py

示例4: plot_absline

# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import generate_voigt [as 别名]
def plot_absline(wrest,logN,b):
    """Plot an absorption line with N,b properties

    Parameters
    ----------
    wrest : float
      Rest wavelength (Ang)
    logN : float
      Log10 column
    b : float
      Doppler parameter (km/s)
    """
    import numpy as np
    from linetools.spectra.xspectrum1d import XSpectrum1D
    from linetools.lists.linelist import LineList
    from linetools.spectralline import AbsLine
    from linetools.analysis import voigt as lav
    from astropy import units as u

    # Search for the closest absline
    aline = AbsLine(wrest*u.AA, closest=True)

    # Generate a fake wavelength array near the line
    wvoff = 50. # Ang
    dwv = wrest/100000. # Ang (echelle)
    wave = np.arange(wrest-wvoff, wrest+wvoff, dwv)

    # Generate spectrum with voigt
    aline.attrib['N'] = logN
    aline.attrib['b'] = b * u.km/u.s
    xspec = aline.generate_voigt(wave=wave*u.AA)
    xspec.constant_sig(0.1) # S/N = 10 per pix


    # Calculate EW
    aline.analy['spec'] = xspec
    aline.analy['wvlim'] = np.array([wrest-15., wrest+15])*u.AA
    aline.measure_ew()
    print(aline)
    print('EW = {:g}'.format(aline.attrib['EW']))

    # Plot
    xspec.plot()
开发者ID:ntejos,项目名称:linetools,代码行数:45,代码来源:linet_absline.py


注:本文中的linetools.spectralline.AbsLine.generate_voigt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。