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


Python AbsLine.analy['spec']方法代码示例

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


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

示例1: test_stack_plot

# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import analy['spec'] [as 别名]
def test_stack_plot(show=False):
    abslin1 = AbsLine(1548.195*u.AA)
    abslin2 = AbsLine('CIV 1550')
    # no spectrum first
    ltap.stack_plot([abslin1], show=show)
    # Set spectrum
    spec = ltsio.readspec(data_path('UM184_nF.fits'))  # already normalized
    abslin1.analy['spec'] = spec
    abslin1.analy['wvlim'] = [6079.78, 6168.82]*u.AA
    abslin1.attrib['z'] = 2.92929
    ltap.stack_plot([abslin1], show=show)
    # second line
    abslin2.analy['spec'] = spec
    abslin2.analy['wvlim'] = [6079.78, 6168.82]*u.AA
    abslin2.attrib['z'] = 2.92929
    ltap.stack_plot([abslin1, abslin2], show=show)
开发者ID:jnburchett,项目名称:linetools,代码行数:18,代码来源:test_plots.py

示例2: mk_comp

# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import analy['spec'] [as 别名]
def mk_comp(ctype,vlim=[-300.,300]*u.km/u.s,add_spec=False, use_rand=True,
            add_trans=False, zcomp=2.92939, b=20*u.km/u.s):
    # Read a spectrum Spec
    if add_spec:
        xspec = lsio.readspec(lt_path+'/spectra/tests/files/UM184_nF.fits')
    else:
        xspec = None
    # AbsLines
    if ctype == 'HI':
        all_trans = ['HI 1215', 'HI 1025']
    elif ctype == 'SiII':
        all_trans = ['SiII 1260', 'SiII 1304', 'SiII 1526', 'SiII 1808']
        if add_trans:
            all_trans += ['SiII 1193']
    abslines = []
    for trans in all_trans:
        iline = AbsLine(trans, z=zcomp)
        if use_rand:
            rnd = np.random.rand()
        else:
            rnd = 0.
        iline.attrib['logN'] = 13.3 + rnd
        iline.attrib['sig_logN'] = 0.15
        iline.attrib['flag_N'] = 1
        iline.attrib['b'] = b
        iline.analy['spec'] = xspec
        iline.limits.set(vlim)
        _,_ = ltaa.linear_clm(iline.attrib)  # Loads N, sig_N
        abslines.append(iline)
    # Component
    abscomp = AbsComponent.from_abslines(abslines)
    return abscomp, abslines
开发者ID:lwymarie,项目名称:linetools,代码行数:34,代码来源:test_use_abscomp.py

示例3: test_voigt_model

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

示例4: stack_plot

# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import analy['spec'] [as 别名]
 def stack_plot(self, inp, use_lines=None, ymnx=None, add_lines=None, **kwargs):
     """ Generate a stack plot of the key lines for a given COS-Halos system
     Parameters
     ----------
     inp : int or tuple
       int -- Index of the cgm_abs list
       tuple -- (field,gal_id)
     add_lines : list, optional
       List of additional lines to plot
     """
     # Init
     from linetools.analysis import plots as ltap
     if ymnx is None:
         ymnx=(-0.1,1.2)
     cgm_abs = self[inp]
     abs_lines = []
     # Setup the lines (defaults to a key seto)
     if use_lines is None:
         use_lines = [1215.6700, 1025.7223, 1334.5323, 977.020, 1031.9261, 1037.6167,
                      1260.4221, 1206.500, 1393.7550, 2796.352]*u.AA
         if add_lines is not None:
             use_lines = list(use_lines.value) + add_lines
             use_lines.sort()
             use_lines = use_lines*u.AA
     for iline in use_lines:
         spec = self.load_bg_cos_spec(inp, iline)
         if spec is None:
             print('Skipping {:g}. Assuming no coverage'.format(iline))
         aline = AbsLine(iline, closest=True)
         aline.analy['spec'] = spec
         aline.attrib['z'] = cgm_abs.galaxy.z
         abs_lines.append(aline)
     # Execute
     ltap.stack_plot(abs_lines, vlim=[-400., 400]*u.km/u.s, ymnx=ymnx, **kwargs)
开发者ID:pyigm,项目名称:pyigm,代码行数:36,代码来源:cos_halos.py

示例5: abslines_from_VPfile

# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import analy['spec'] [as 别名]
def abslines_from_VPfile(parfile,specfile=None,ra=None,dec=None):
    '''
    Takes a joebvp parameter file and builds a list of linetools AbsLines from the measurements therein.

    Parameters
    ----------
    parfile : str
        Name of the parameter file in the joebvp format
    ra : float, optional
        Right Ascension of the QSO in decimal degrees
    dec : float, optional
        Declination of the QSO in decimal degress

    Returns
    -------
    abslinelist: list
        List of AbsLine objects
    '''
    from linetools.spectralline import AbsLine
    from linetools.lists.linelist import LineList
    import astropy.units as u
    llist = LineList('ISM')
    if specfile!=None:
        spec=readspec(specfile) # Allow spectrum file to be declared in call
    linetab = ascii.read(parfile) # Read parameters from file
    linetab['restwave']=linetab['restwave']*u.AA
    abslinelist = [] # Initiate list to populate
    for i,row in enumerate(linetab):
        ### Check to see if errors for this line are defined
        colerr,berr,velerr=get_errors(linetab,i)
        ### Adjust velocity limits according to centroid errors and limits from file
        vcentmin = row['vel']-velerr
        vcentmax = row['vel']+velerr
        v1 = vcentmin + row['vlim1']
        v2 = vcentmax + row['vlim2']
        line=AbsLine(row['restwave']*u.AA, z=row['zsys'],closest=True, linelist=llist)
        vlims=[v1,v2]*u.km/u.s
        line.limits.set(vlims)
        ### Set other parameters
        line.attrib['logN'] = row['col']
        line.attrib['sig_logN'] = colerr
        line.attrib['b'] = row['bval'] * u.km/u.s
        line.attrib['sig_b'] = berr * u.km/u.s
        line.attrib['vel'] = row['vel'] * u.km/u.s
        ### Attach the spectrum to this AbsLine but check first to see if this one is same as previous
        if specfile==None:
            if i==0:
                spec=readspec(row['specfile'])
            elif row['specfile']!=linetab['specfile'][i-1]:
                spec=readspec(row['specfile'])
            else:
                pass
        line.analy['spec']=spec
        ### Add it to the list and go on
        abslinelist.append(line)
    return abslinelist
开发者ID:jnburchett,项目名称:joebvp,代码行数:58,代码来源:utils.py

示例6: plot_absline

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

示例7: test_measurekin_absline

# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import analy['spec'] [as 别名]
def test_measurekin_absline():
    # Test Simple kinematics
    abslin = AbsLine('NiII 1741',z=2.307922)

    # Set spectrum
    abslin.analy['spec'] = lsio.readspec(data_path('PH957_f.fits'))
    abslin.limits.set([-70., 70.]*u.km/u.s)

    # Measure Kin
    abslin.measure_kin()
    np.testing.assert_allclose(abslin.attrib['kin']['Dv'].value, 75.)
    np.testing.assert_allclose(abslin.attrib['kin']['fedg'], 0.20005782376000183)
开发者ID:linetools,项目名称:linetools,代码行数:14,代码来源:test_absline_anly.py

示例8: test_dicts

# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import analy['spec'] [as 别名]
def test_dicts():
    # Init HI Lya
    abslin = AbsLine(1215.6700*u.AA)
    abslin.analy['spec'] = 'tmp.fits'
    adict = abslin.to_dict()
    assert isinstance(adict, dict)
    # Write
    #pdb.set_trace()
    ltu.savejson('tmp.json', adict, overwrite=True)
    # Read
    newdict = ltu.loadjson('tmp.json')
    newlin = SpectralLine.from_dict(newdict)
    assert newlin.name == 'HI 1215'
开发者ID:banados,项目名称:linetools,代码行数:15,代码来源:test_init_absline.py

示例9: test_gaussew_absline

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

示例10: test_synthesize_colm

# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import analy['spec'] [as 别名]
def test_synthesize_colm():
    # Read a spectrum Spec
    xspec = lsio.readspec(lt_path+'/spectra/tests/files/UM184_nF.fits')
    # AbsLines
    SiIItrans = ['SiII 1260', 'SiII 1304', 'SiII 1526', 'SiII 1808']
    abslines = []
    for trans in SiIItrans:
        iline = AbsLine(trans)
        iline.attrib['z'] = 2.92939
        iline.analy['vlim'] = [-250.,80.]*u.km/u.s
        iline.analy['spec'] = xspec
        abslines.append(iline)
    # Component
    abscomp = AbsComponent.from_abslines(abslines)
    # Column
    abscomp.synthesize_colm(redo_aodm=True)
    # Test
    np.testing.assert_allclose(abscomp.logN,13.594447075294818)
开发者ID:nhmc,项目名称:linetools,代码行数:20,代码来源:test_use_abscomp.py

示例11: test_boxew_absline

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

示例12: test_cog

# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import analy['spec'] [as 别名]
def test_cog():
    # Read a spectrum Spec
    xspec = lsio.readspec(lt_path+'/spectra/tests/files/UM184_nF.fits')
    # AbsLines
    SiIItrans = ['SiII 1260', 'SiII 1304', 'SiII 1526', 'SiII 1808']
    abslines = []
    for trans in SiIItrans:
        iline = AbsLine(trans)
        iline.attrib['z'] = 2.92939
        iline.analy['vlim'] = [-250.,80.]*u.km/u.s
        iline.analy['spec'] = xspec
        abslines.append(iline)
    # Component
    abscomp = AbsComponent.from_abslines(abslines)
    # COG
    COG_dict = abscomp.cog(redo_EW=True)
    # Test
    np.testing.assert_allclose(COG_dict['logN'],13.693355878125537)
    np.testing.assert_allclose(COG_dict['sig_logN'],0.054323725737309987)
开发者ID:nhmc,项目名称:linetools,代码行数:21,代码来源:test_use_abscomp.py

示例13: plot_absline

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

示例14: test_boxew_absline

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

示例15: test_dicts

# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import analy['spec'] [as 别名]
def test_dicts():
    # Init HI Lya
    abslin = AbsLine(1215.6700*u.AA)
    abslin.analy['spec'] = 'tmp.fits'
    adict = abslin.to_dict()
    assert isinstance(adict, dict)
    # Write
    #pdb.set_trace()
    ltu.savejson('tmp.json', adict, overwrite=True)
    # Read
    newdict = ltu.loadjson('tmp.json')
    newlin = SpectralLine.from_dict(newdict)
    assert newlin.name == 'HI 1215'
    # Old dict for compatability
    newdict.pop('limits')
    newdict['analy']['vlim'] = [-150,150]*u.km/u.s
    newdict['attrib']['z'] = 0.5
    tmp3 = SpectralLine.from_dict(newdict)
    assert newlin.name == 'HI 1215'
开发者ID:jnburchett,项目名称:linetools,代码行数:21,代码来源:test_init_absline.py


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