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


Python AbsLine.measure_ew方法代码示例

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


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

示例1: plot_absline

# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import measure_ew [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

示例2: test_gaussew_absline

# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import measure_ew [as 别名]
def test_gaussew_absline():
    # Text Gaussian EW evaluation
    # Init CIV 1548
    abslin = AbsLine('CIV 1548', z=2.9304)

    # Set spectrum
    abslin.analy['spec'] = lsio.readspec(data_path('UM184_nF.fits')) # Fumagalli+13 MagE spectrum
    abslin.limits.set([6080.78, 6087.82]*u.AA)
    # Measure EW (not rest-frame)
    abslin.measure_ew(flg=2)
    ew = abslin.attrib['EW']

    np.testing.assert_allclose(ew.value, 1.02,atol=0.01)
    assert ew.unit == u.AA

    abslin.measure_ew(flg=2,initial_guesses=(0.5,6081,1))
开发者ID:linetools,项目名称:linetools,代码行数:18,代码来源:test_absline_anly.py

示例3: test_boxew_absline

# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import measure_ew [as 别名]
def test_boxew_absline():
    # Text boxcar EW evaluation
        # Init CIV 1548
    abslin = AbsLine('CIV 1548', z=2.9304)

    # Set spectrum
    abslin.analy['spec'] = lsio.readspec(data_path('UM184_nF.fits')) # Fumagalli+13 MagE spectrum
    abslin.limits.set([6080.78, 6087.82]*u.AA)
    # Measure EW (not rest-frame)
    abslin.measure_ew()
    ew = abslin.attrib['EW']

    np.testing.assert_allclose(ew.value, 0.9935021012055584)
    assert ew.unit == u.AA

    abslin.measure_restew()
    restew = abslin.attrib['EW']
    np.testing.assert_allclose(restew.value, 0.9935021012055584/(1+abslin.z))
开发者ID:linetools,项目名称:linetools,代码行数:20,代码来源:test_absline_anly.py

示例4: plot_absline

# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import measure_ew [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

示例5: test_boxew_absline

# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import measure_ew [as 别名]
def test_boxew_absline():
    # Text boxcar EW evaluation
        # Init CIV 1548
    abslin = AbsLine(1548.195*u.AA)

    # Set spectrum
    abslin.analy['spec'] = lsio.readspec(data_path('UM184_nF.fits')) # Fumagalli+13 MagE spectrum
    abslin.analy['wvlim'] = [6080.78, 6087.82]*u.AA
    # Measure EW (not rest-frame)
    abslin.measure_ew()
    ew = abslin.attrib['EW']

    np.testing.assert_allclose(ew.value, 0.9935021012055584)
    assert ew.unit == u.AA

    abslin.measure_restew()
    #import pdb
    #pdb.set_trace()
    np.testing.assert_allclose(ew.value, 0.9935021012055584/(1+abslin.attrib['z']))
开发者ID:nhmc,项目名称:linetools,代码行数:21,代码来源:test_absline_anly.py

示例6: example_ew

# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import measure_ew [as 别名]
def example_ew(outfil='Figures/example_ew.pdf'):
    """ A simple example of EW
    """

    # Generate a simple Lya line
    lya = AbsLine(1215.6700*u.AA)
    NHI = 13.6
    bval = 30.
    lya.attrib['N'] = 10.**(NHI)/u.cm**2
    lya.attrib['b'] = bval * u.km/u.s
    lya.attrib['z'] = 0.

    # Spectrum
    wave = np.linspace(1180., 1250., 20000) * u.AA
    f_obs = ltav.voigt_from_abslines(wave, [lya])
    f_obs.sig = 0.1*np.ones(f_obs.npix)

    # Measure EW
    lya.analy['spec'] = f_obs
    lya.analy['wvlim'] = [1210.,1220]*u.AA
    lya.measure_ew()

    # Initialize
    xmnx = (1214.2, 1217.2)
    ymnx = (-0.05, 1.08)
    ms = 7.

    # Start the plot
    pp = PdfPages(outfil)
    fig = plt.figure(figsize=(8.5, 3.7))

    plt.clf()
    gs = gridspec.GridSpec(1,2)

    # Lya line
    ax = plt.subplot(gs[0,0])
    #ax.xaxis.set_minor_locator(plt.MultipleLocator(0.5))
    #ax.xaxis.set_major_locator(plt.MultipleLocator(20.))
    #ax.yaxis.set_minor_locator(plt.MultipleLocator(0.1))
    #ax.yaxis.set_major_locator(plt.MultipleLocator(0.2))
    ax.set_xlim(xmnx)
    ax.set_ylim(ymnx) 
    ax.set_ylabel('Normalized Flux')
    ax.set_xlabel('Wavelength (Angstroms)')

    lw = 2
    ax.plot(f_obs.wavelength, f_obs.flux, 'k', linewidth=lw)
    ax.fill_between(f_obs.wavelength.value, f_obs.flux.value, np.ones(f_obs.npix),
        color='blue', alpha=0.7)

    # Label
    csz = 12.
    cNHI = '{:0.1f}'.format(NHI)
    ax.text(0.05, 0.2, r'$N_{\rm HI} = 10^{'+cNHI+r'} \rm cm^{-2}$',
        transform=ax.transAxes, size=csz, ha='left')#, bbox={'facecolor':'white'})
    ax.text(0.05, 0.12, r'$b = $'+'{:d} km/s'.format(int(bval)),
        transform=ax.transAxes, size=csz, ha='left')#, bbox={'facecolor':'white'})
    ax.text(0.05, 0.04, r'$W_\lambda = $'+'{:0.2f} Ang'.format(lya.attrib['EW'].value),
        transform=ax.transAxes, size=csz, ha='left')#, bbox={'facecolor':'white'})

    # EW panel
    ax = plt.subplot(gs[0,1])
    ax.set_xlim(xmnx)
    ax.set_ylim(ymnx) 
    ax.set_ylabel('Normalized Flux')
    ax.set_xlabel('Wavelength (Angstroms)')

    xval = [0]+[1215.67-lya.attrib['EW'].value/2]*2 + [1215.67+lya.attrib['EW'].value/2]*2 + [1500]
    ax.plot(xval, [1,1,0,0,1,1], 'k', linewidth=lw)
    ax.fill_between(np.array([lya.attrib['EW'].value/2]*2)*np.array([-1,1])+1215.67,
        [0,0], [1,1], color='red', alpha=0.7)

    # Layout and save
    print('Writing {:s}'.format(outfil))
    plt.tight_layout(pad=0.2,h_pad=0.0,w_pad=0.4)
    plt.subplots_adjust(hspace=0)
    pp.savefig(bbox_inches='tight')
    plt.close()
    # Finish
    pp.close()
开发者ID:Tuo-Ji,项目名称:SaasFee2016,代码行数:82,代码来源:saasfee16_figures.py


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