本文整理汇总了Python中linetools.spectralline.AbsLine.analy['wvlim']方法的典型用法代码示例。如果您正苦于以下问题:Python AbsLine.analy['wvlim']方法的具体用法?Python AbsLine.analy['wvlim']怎么用?Python AbsLine.analy['wvlim']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类linetools.spectralline.AbsLine
的用法示例。
在下文中一共展示了AbsLine.analy['wvlim']方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_stack_plot
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import analy['wvlim'] [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)
示例2: mk_comp
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import analy['wvlim'] [as 别名]
def mk_comp(ctype,vlim=[-300.,300]*u.km/u.s,add_spec=False, use_rand=True,
add_trans=False, zcomp=2.92939):
# 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)
iline.attrib['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.analy['spec'] = xspec
iline.analy['vlim'] = vlim
iline.analy['wvlim'] = iline.wrest * (1 + zcomp + ltu.give_dz(vlim, zcomp))
_,_ = ltaa.linear_clm(iline.attrib) # Loads N, sig_N
abslines.append(iline)
# Component
abscomp = AbsComponent.from_abslines(abslines)
return abscomp, abslines
示例3: plot_absline
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import analy['wvlim'] [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)
示例4: test_coincident_line
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import analy['wvlim'] [as 别名]
def test_coincident_line():
# Init AbsLines
line1 = AbsLine(1215.6700*u.AA)
line2 = AbsLine('CII 1334')
# expected errors
try:
answer = line1.coincident_line(line2)
except ValueError:
pass
line1.analy['wvlim'] = (1500,1510)*u.AA
try:
answer = line1.coincident_line(line2)
except ValueError:
pass
line2.analy['wvlim'] = (1509,1520)*u.AA
# expected overlap
assert line1.coincident_line(line2)
assert line2.coincident_line(line1)
# not expected overlap
line2.analy['wvlim'] = (1510.1,1520)*u.AA
assert not line1.coincident_line(line2)
assert not line2.coincident_line(line1)
示例5: test_aodm_absline
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import analy['wvlim'] [as 别名]
def test_aodm_absline():
# 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
#
abslin.measure_aodm()
N, sigN, flgN = [abslin.attrib[key] for key in ['N','sigN','flagN']]
np.testing.assert_allclose(N.value, 300009659372018.7)
assert N.unit == 1/u.cm**2
assert flgN == 1
# Now velocity limits
abslin.analy['wvlim'] = np.zeros(2)*u.AA
abslin.analy['vlim'] = (-150., 150.)*u.km/u.s
abslin.attrib['z'] = 2.92929
#
abslin.measure_aodm()
N, sigN, flgN = [abslin.attrib[key] for key in ['N','sigN','flagN']]
np.testing.assert_allclose(N.value, 80369196079224.42)
示例6: plot_absline
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import analy['wvlim'] [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()
示例7: test_boxew_absline
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import analy['wvlim'] [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']))
示例8: test_gaussew_absline
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import analy['wvlim'] [as 别名]
def test_gaussew_absline():
# Text Gaussian 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(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))
np.testing.assert_allclose(ew.value, 1.02,atol=0.01)
abslin.measure_restew()
np.testing.assert_allclose(ew.value, 1.02/(1+abslin.attrib['z']),atol=0.01)
示例9: example_ew
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import analy['wvlim'] [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()