本文整理汇总了Python中linetools.isgm.abscomponent.AbsComponent类的典型用法代码示例。如果您正苦于以下问题:Python AbsComponent类的具体用法?Python AbsComponent怎么用?Python AbsComponent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AbsComponent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_list_of_abslines
def test_list_of_abslines():
radec = SkyCoord(ra=123.1143*u.deg, dec=-12.4321*u.deg)
# HI Lya, Lyb
lya = AbsLine(1215.670*u.AA)
lya.analy['vlim'] = [-300.,300.]*u.km/u.s
lya.attrib['z'] = 2.92939
lyb = AbsLine(1025.7222*u.AA)
lyb.analy['vlim'] = [-300.,300.]*u.km/u.s
lyb.attrib['z'] = lya.attrib['z']
abscomp = AbsComponent.from_abslines([lya,lyb])
abscomp.coord = radec
# SiII
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
abslines.append(iline)
#
SiII_comp = AbsComponent.from_abslines(abslines)
SiII_comp.coord = radec
# Instantiate
gensys = GenericAbsSystem.from_components([abscomp,SiII_comp])
# Now the list
abslines = gensys.list_of_abslines()
# Test
assert len(abslines) == 6
# Grab one line
lyb = gensys.get_absline('HI 1025')
np.testing.assert_allclose(lyb.wrest.value, 1025.7222)
lyb = gensys.get_absline(1025.72*u.AA)
np.testing.assert_allclose(lyb.wrest.value, 1025.7222)
示例2: __init__
def __init__(self, z, wrest, vlim=[-300.,300]*u.km/u.s,
linelist=None):
# Init
self.init_wrest = wrest
self.linelist = linelist
self.lines = []
self.init_lines()
# Generate with type
radec = (0*u.deg,0*u.deg)
Zion = (self.lines[0].data['Z'],self.lines[0].data['ion'])
Ej = self.lines[0].data['Ej']
AbsComponent.__init__(self,radec, Zion, z, vlim, Ej, comment='None')
# Init cont.
self.attrib = {'N': 0./u.cm**2, 'Nsig': 0./u.cm**2, 'flagN': 0, # Column
'logN': 0., 'sig_logN': 0.,
'b': 0.*u.km/u.s, 'bsig': 0.*u.km/u.s, # Doppler
'z': self.zcomp, 'zsig': 0.,
'Quality': 'None'}
# Sync
self.sync_lines()
# Use different naming convention here
self.name = 'z{:.5f}_{:s}'.format(
self.zcomp,self.lines[0].data['name'].split(' ')[0])
示例3: test_multi_components
def test_multi_components():
radec = SkyCoord(ra=123.1143*u.deg, dec=-12.4321*u.deg)
# HI Lya, Lyb
lya = AbsLine(1215.670*u.AA)
lya.analy['vlim'] = [-300.,300.]*u.km/u.s
lya.attrib['z'] = 2.92939
lyb = AbsLine(1025.7222*u.AA)
lyb.analy['vlim'] = [-300.,300.]*u.km/u.s
lyb.attrib['z'] = lya.attrib['z']
abscomp = AbsComponent.from_abslines([lya,lyb])
abscomp.coord = radec
# SiII
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
abslines.append(iline)
#
SiII_comp = AbsComponent.from_abslines(abslines)
SiII_comp.coord = radec
# Instantiate
LLSsys = GenericAbsSystem.from_components([abscomp,SiII_comp])
# Test
assert len(LLSsys._components) == 2
示例4: test_add_component
def test_add_component():
radec = SkyCoord(ra=123.1143*u.deg, dec=-12.4321*u.deg)
# HI Lya, Lyb
lya = AbsLine(1215.670*u.AA)
lya.analy['vlim'] = [-300.,300.]*u.km/u.s
lya.attrib['z'] = 2.92939
lya.attrib['N'] = 1e17 / u.cm**2
lyb = AbsLine(1025.7222*u.AA)
lyb.analy['vlim'] = [-300.,300.]*u.km/u.s
lyb.attrib['z'] = lya.attrib['z']
abscomp = AbsComponent.from_abslines([lya,lyb])
abscomp.coord = radec
# Instantiate
abssys = GenericAbsSystem.from_components([abscomp])
# New component
oi = AbsLine('OI 1302')
oi.analy['vlim'] = [-300.,300.]*u.km/u.s
oi.attrib['z'] = lya.attrib['z']
abscomp2 = AbsComponent.from_abslines([oi])
abscomp2.coord = radec
# Standard
assert abssys.add_component(abscomp2)
# Fail
abssys = GenericAbsSystem.from_components([abscomp])
abscomp2.vlim = [-400.,300.]*u.km/u.s
assert not abssys.add_component(abscomp2)
# Overlap
assert abssys.add_component(abscomp2, overlap_only=True)
示例5: test_abscomp_H2
def test_abscomp_H2():
Zion = (-1, -1) # temporary code for molecules
Ntuple = (1, 17, -1) # initial guess for Ntuple (needs to be given for adding lines from linelist)
coord = SkyCoord(0,0, unit='deg')
z = 0.212
vlim = [-100., 100.] * u.km/u.s
comp = AbsComponent(coord, Zion, z, vlim, Ntup=Ntuple)
comp.add_abslines_from_linelist(llist='H2', init_name="B19-0P(1)", wvlim=[1100, 5000]*u.AA)
assert len(comp._abslines) == 7
示例6: test_fromtodict
def test_fromtodict():
SiIIcomp1,_ = mk_comp('SiII',vlim=[-300.,50.]*u.km/u.s, add_spec=True)
cdict = SiIIcomp1.to_dict()
#
assert isinstance(cdict, dict)
assert cdict['Zion'] == (14, 2)
# And instantiate
newcomp = AbsComponent.from_dict(cdict)
assert isinstance(newcomp, AbsComponent)
newcomp = AbsComponent.from_dict(cdict, coord=SkyCoord(0,0, unit='deg'))
示例7: fill_lls_lines
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))
示例8: mk_comp
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
示例9: test_init_single_absline
def test_init_single_absline():
# Single AbsLine
lya = AbsLine(1215.670*u.AA)
lya.analy['vlim'] = [-300.,300.]*u.km/u.s
lya.attrib['z'] = 2.92939
abscomp = AbsComponent.from_abslines([lya])
# Test
assert abscomp.Zion[0] == 1
np.testing.assert_allclose(abscomp.zcomp,2.92939)
示例10: test_init_single_absline
def test_init_single_absline():
# Single AbsLine
lya = AbsLine(1215.670*u.AA,z=2.92939)
lya.limits.set([-300.,300.]*u.km/u.s)
abscomp = AbsComponent.from_abslines([lya])
# Test
assert abscomp.Zion[0] == 1
np.testing.assert_allclose(abscomp.zcomp,2.92939)
print(abscomp)
示例11: lyman_comp
def lyman_comp(radec):
# HI Lya, Lyb
lya = AbsLine(1215.670*u.AA)
lya.analy['vlim'] = [-300.,300.]*u.km/u.s
lya.attrib['z'] = 2.92939
lya.attrib['N'] = 1e17 / u.cm**2
lyb = AbsLine(1025.7222*u.AA)
lyb.analy['vlim'] = [-300.,300.]*u.km/u.s
lyb.attrib['z'] = lya.attrib['z']
abscomp = AbsComponent.from_abslines([lya,lyb])
abscomp.coord = radec
return abscomp
示例12: build_components_from_abslines
def build_components_from_abslines(iabslines, clmdict=None, coord=None):
""" Generate a list of AbsComponent from a list of abslines
Groups lines with like Zion, Ej, (and A; future)
Parameters
----------
abslines : list
List of AbsLine objects
May be ignored if clmdict is passed in
clmdict : dict, optional
If present, build the abslines list from this dict
coord : SkyCoord, optional
Required if clmdict is used
Returns
-------
components :
list of AbsComponent objects
"""
if clmdict is None:
abslines = iabslines
else:
abslines = []
vmin, vmax = 9999.0, -9999.0
for wrest in clmdict["lines"].keys():
vmin = min(vmin, clmdict["lines"][wrest].analy["vlim"][0].value)
vmax = max(vmax, clmdict["lines"][wrest].analy["vlim"][1].value)
clmdict["lines"][wrest].attrib["coord"] = coord
abslines.append(clmdict["lines"][wrest])
# Test
if not isinstance(abslines, list):
raise IOError("Need a list of AbsLine objects")
# Identify unique Zion, Ej combinations in the lines
uZiE = np.array(
[
iline.data["Z"] * 1000000 + iline.data["ion"] * 10000 + iline.data["Ej"].to("1/cm").value
for iline in abslines
]
)
uniZi, auidx = np.unique(uZiE, return_index=True)
# Loop to build components
components = []
for uidx in auidx:
# Synthesize lines with like Zion, Ej
mtZiE = np.where(uZiE == uZiE[uidx])[0]
lines = [abslines[ii] for ii in mtZiE] # Need a list
# Generate component
components.append(AbsComponent.from_abslines(lines))
return components
示例13: test_init_multi_absline
def test_init_multi_absline():
# AbsLine(s)
lya = AbsLine(1215.670*u.AA, z=2.92939)
lya.analy['vlim'] = [-300.,300.]*u.km/u.s
lyb = AbsLine(1025.7222*u.AA)
lyb.analy['vlim'] = [-300.,300.]*u.km/u.s
lyb.setz(lya.z)
# Instantiate
abscomp = AbsComponent.from_abslines([lya,lyb])
# Test
assert len(abscomp._abslines) == 2
np.testing.assert_allclose(abscomp.zcomp,2.92939)
示例14: test_init_failures
def test_init_failures():
with pytest.raises(IOError):
AbsComponent.from_abslines('blah')
with pytest.raises(IOError):
AbsComponent.from_abslines(['blah'])
with pytest.raises(IOError):
AbsComponent.from_component('blah')
示例15: test_build_table
def test_build_table():
# AbsLine(s)
lya = AbsLine(1215.670*u.AA)
lya.analy['vlim'] = [-300.,300.]*u.km/u.s
lya.attrib['z'] = 2.92939
lyb = AbsLine(1025.7222*u.AA)
lyb.analy['vlim'] = [-300.,300.]*u.km/u.s
lyb.attrib['z'] = lya.attrib['z']
# Instantiate
abscomp = AbsComponent.from_abslines([lya,lyb])
comp_tbl = abscomp.build_table()
# Test
assert isinstance(comp_tbl,QTable)