本文整理汇总了Python中linetools.spectralline.AbsLine.attrib['b']方法的典型用法代码示例。如果您正苦于以下问题:Python AbsLine.attrib['b']方法的具体用法?Python AbsLine.attrib['b']怎么用?Python AbsLine.attrib['b']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类linetools.spectralline.AbsLine
的用法示例。
在下文中一共展示了AbsLine.attrib['b']方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_voigt_multi_line
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['b'] [as 别名]
def test_voigt_multi_line():
# Wavelength array
wave = np.linspace(3644, 3650, 100)*u.AA
imn = np.argmin(np.abs(wave.value-3646.2))
# HI line
abslin = AbsLine(1215.670*u.AA, z=2.)
abslin.attrib['N'] = 10**17.5/u.cm**2
abslin.attrib['b'] = 20.*u.km/u.s
# DI line
abslin2 = AbsLine('DI 1215', z=2.)
abslin2.attrib['N'] = 10**13./u.cm**2
abslin2.attrib['b'] = 15.*u.km/u.s
# Voigt
vmodel3 = lav.voigt_from_abslines(wave,[abslin,abslin2])
np.testing.assert_allclose(vmodel3.flux[imn].value,0.5715512949324375)
示例2: test_voigt_model
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['b'] [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
示例3: fill_lls_lines
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['b'] [as 别名]
def fill_lls_lines(self, bval=20.*u.km/u.s, do_analysis=1):
"""
Generate an HI line list for an LLS.
Goes into self.lls_lines
Now generates a component too.
Should have it check for an existing HI component..
Parameters
----------
bval : float, optional
Doppler parameter in km/s
do_analysis : int, optional
flag for analysis
"""
from linetools.lists import linelist as lll
# May be replaced by component class (as NT desires)
HIlines = lll.LineList('HI')
self.lls_lines = []
Nval = 10**self.NHI / u.cm**2
for lline in HIlines._data:
aline = AbsLine(lline['wrest'], linelist=HIlines)
# Attributes
aline.attrib['N'] = Nval
aline.attrib['b'] = bval
aline.attrib['z'] = self.zabs
aline.analy['vlim'] = self.vlim
aline.analy['do_analysis'] = do_analysis
aline.attrib['coord'] = self.coord
self.lls_lines.append(aline)
# Generate a component (should remove any previous HI)
self.add_component(AbsComponent.from_abslines(self.lls_lines))
示例4: mk_comp
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['b'] [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
示例5: add_DLA
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['b'] [as 别名]
def add_DLA(self,z, NHI=20.3,bval=30.*u.km/u.s, comment='None', model=True):
"""Generate a new DLA
"""
# Lya, Lyb
dla_lines = [] # For convenience
for trans in ['HI 1025', 'HI 1215']:
iline = AbsLine(trans)
iline.attrib['z'] = z
iline.attrib['N'] = 10**NHI / u.cm**2
iline.attrib['b'] = bval
iline.attrib['coord'] = SkyCoord(ra=0*u.deg,dec=0*u.deg)
dla_lines.append(iline)
# Generate system
new_sys = DLASystem.from_abslines(dla_lines) #(0*u.deg,0*u.deg),z,None,NHI)
new_sys.bval = bval # This is not standard, but for convenience
new_sys.comment = comment
new_sys.dla_lines = dla_lines # Also for convenience
# Name
self.count_dla += 1
new_sys.label = 'DLA_Sys_{:d}'.format(self.count_dla)
# Add
self.abssys_widg.add_fil(new_sys.label)
self.abssys_widg.all_abssys.append(new_sys)
self.abssys_widg.abslist_widget.item(
len(self.abssys_widg.all_abssys)).setSelected(True)
# Update
self.llist['Plot'] = False # Turn off metal-lines
if model: # For dealing with initialization
self.update_model()
示例6: fill_lls_lines
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['b'] [as 别名]
def fill_lls_lines(self, bval=20.*u.km/u.s):
"""
Generate an HI line list for an LLS.
Goes into self.lls_lines
Parameters
----------
bval : float (20.) Doppler parameter in km/s
"""
from linetools.lists import linelist as lll
from linetools.spectralline import AbsLine
# May be replaced by component class (as NT desires)
HIlines = lll.LineList('HI')
self.lls_lines = []
for lline in HIlines._data:
aline = AbsLine(lline['wrest'],linelist=HIlines)
# Attributes
aline.attrib['N'] = self.NHI
aline.attrib['b'] = bval
aline.attrib['z'] = self.zabs
# Could set RA and DEC too
aline.attrib['RA'] = self.coord.ra
aline.attrib['DEC'] = self.coord.dec
self.lls_lines.append(aline)
示例7: abslines_from_VPfile
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['b'] [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
示例8: dla_vary_NHI
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['b'] [as 别名]
def dla_vary_NHI(outfil='Figures/dla_vary_NHI.pdf'):
""" DLA profiles with NHI varying
"""
# Wavelength array for my 'perfect' instrument
wave = np.linspace(1160., 1270., 20000) * u.AA
vel = (wave-1215.67*u.AA)/(1215.67*u.AA) * const.c.to('km/s')
# Lya line
lya = AbsLine(1215.6700*u.AA)
#lya.attrib['N'] = 10.**(13.6)/u.cm**2
lya.attrib['b'] = 30 * u.km/u.s
lya.attrib['z'] = 0.
aNHI = [20.3, 21., 21.5, 22.]
# Start the plot
xmnx = (-10000, 10000)
ymnx = (0., 1.0)
pp = PdfPages(outfil)
fig = plt.figure(figsize=(8.0, 5.0))
plt.clf()
gs = gridspec.GridSpec(1,1)
# Lya line
ax = plt.subplot(gs[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('Relative Velocity (km/s)')
lw = 1.5
# Data
for NHI in aNHI:
lyai = copy.deepcopy(lya)
lyai.attrib['N'] = 10**NHI / u.cm**2
f_obsi = ltav.voigt_from_abslines(wave, [lyai])
ax.plot(vel, f_obsi.flux, linewidth=lw,
label=r'$\log N_{\rm HI} = $'+'{:0.2f}'.format(NHI))
# Legend
legend = plt.legend(loc='lower left', scatterpoints=1, borderpad=0.3,
handletextpad=0.3, fontsize='large', numpoints=1)
xputils.set_fontsize(ax, 17.)
# 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()
示例9: plot_absline
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['b'] [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)
示例10: test_voigt_sngl_tau
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['b'] [as 别名]
def test_voigt_sngl_tau():
# 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
# Tau
tau = lav.voigt_from_abslines(wave,abslin,ret='tau')
np.testing.assert_allclose(tau[imn], 2.9681283001576779)
示例11: test_voigt_sngl_line
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['b'] [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)
示例12: plot_absline
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['b'] [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()
示例13: add_forest
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['b'] [as 别名]
def add_forest(self,inp,z):
'''Add a Lya/Lyb forest line
'''
from xastropy.igm.abs_sys.abssys_utils import GenericAbsSystem
forest = GenericAbsSystem((0.*u.deg,0.*u.deg), z, [-300.,300.]*u.km/u.s)
# NHI
NHI_dict = {'6':12.,'7':13.,'8':14.,'9':15.}
forest.NHI=NHI_dict[inp]
# Lines
for name in ['HI 1215','HI 1025', 'HI 972']:
aline = AbsLine(name,
linelist=self.llist[self.llist['List']])
# Attributes
aline.attrib['N'] = 10**forest.NHI * u.cm**-2
aline.attrib['b'] = 20.*u.km/u.s
aline.attrib['z'] = forest.zabs
# Append
forest.lines.append(aline)
# Append to forest lines
self.all_forest.append(forest)
示例14: abslines_from_fitpars
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['b'] [as 别名]
def abslines_from_fitpars(fitpars,ra=None,dec=None):
'''
Takes a joebvp parameter array and builds a list of linetools AbsLines from the measurements
Parameters
----------
fitpars : list of lists
The joebvp parameter array that includes line measurements
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')
abslinelist = [] # Initiate list to populate
for i,rw in enumerate(fitpars[0]):
vcent = fitpars[4][i]
v1 = vcent + fitpars[5][i]
v2 = vcent + fitpars[6][i]
line=AbsLine(fitpars[0][i]*u.AA, z=fitpars[3][i],linelist=llist)
vlims=[v1,v2]*u.km/u.s
line.limits.set(vlims)
### Set other parameters
line.attrib['logN'] = fitpars[1][i]
#line.attrib['sig_N'] = colerr
line.attrib['b'] = fitpars[2][i]
#line.attrib['sig_b'] = berr
line.analy['spec']=cfg.spectrum
### Add it to the list and go on
abslinelist.append(line)
return abslinelist
示例15: fig_lya_lines
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['b'] [as 别名]
def fig_lya_lines(outfil='Figures/fig_lya_lines.pdf'):
""" Plot the LLS models
Parameters
----------
Returns
-------
"""
#
# Initialize
ms = 7.
# Start the plot
if outfil is not None:
pp = PdfPages(outfil)
# Dummy line
lya = AbsLine(1215.6700*u.AA)
lya.attrib['N'] = 10.**(13.6)/u.cm**2
b0 = 20
lya.attrib['b'] = b0 * u.km/u.s
lya.attrib['z'] = 0.
# Wavelength array
wave = np.linspace(1200., 1230., 10000) * u.AA
fig = plt.figure(figsize=(8, 5))
plt.clf()
gs = gridspec.GridSpec(1, 2)
lsz = 12.
# NHI varies first
ax = plt.subplot(gs[0])
NHIs = [12., 13., 14., 15.]
# Loop
for jj, NHI in enumerate(NHIs):
lya.attrib['N'] = 10.**(NHI)/u.cm**2
f_obs = ltav.voigt_from_abslines(wave, [lya])
# Plot
ax.plot(f_obs.wavelength, f_obs.flux, '-', label=r'log $N_{\rm HI}$ '+'= {:g}'.format(NHI))
legend = plt.legend(loc='upper right', scatterpoints=1, borderpad=0.3,
handletextpad=0.3, fontsize='small', numpoints=1,
title=r'$b = $'+'{:g} km/s'.format(b0))
ax.xaxis.set_major_locator(plt.MultipleLocator(1.))
ax.xaxis.set_major_locator(MaxNLocator(integer=True))
x_formatter = mpl.ticker.ScalarFormatter(useOffset=False)
ax.xaxis.set_major_formatter(x_formatter)
ax.minorticks_on()
ax.set_xlabel('Wavelength (Ang)')
ax.set_xlim(1214.8, 1216.6)
ax.set_ylabel('Normalized Flux')
# Now b
ax = plt.subplot(gs[1])
N0 = 14.
lya.attrib['N'] = 10.**(N0)/u.cm**2
bvals = [10., 30., 50.]
# Loop
for jj, bval in enumerate(bvals):
lya.attrib['b'] = bval*u.km/u.s
f_obs = ltav.voigt_from_abslines(wave, [lya])
# Plot
velo = f_obs.relative_vel(lya.wrest)
ax.plot(velo, f_obs.flux, '-', label=r'log $N_{\rm HI}$ '+'= {:g}'.format(NHI))
#ax.plot(f_obs.wavelength, f_obs.flux, '-', label=r'$b$ '+'= {:g} km/s'.format(bval))
legend = plt.legend(loc='lower right', scatterpoints=1, borderpad=0.3,
handletextpad=0.3, fontsize='small', numpoints=1,
title=r'log $N_{\rm HI} =$'+'{:g}'.format(N0))
ax.set_xlabel('Relative Velocity (km/s)')
ax.set_xlim(-150., 150.)
ax.set_ylabel('Normalized Flux')
# Layout and save
print('Writing {:s}'.format(outfil))
plt.tight_layout(pad=0.2,h_pad=0.1,w_pad=0.2)
pp.savefig(bbox_inches='tight')
plt.close()
# Finish
pp.close()