本文整理汇总了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
示例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)
示例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)
示例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()