本文整理汇总了Python中linetools.spectralline.AbsLine.attrib['coord']方法的典型用法代码示例。如果您正苦于以下问题:Python AbsLine.attrib['coord']方法的具体用法?Python AbsLine.attrib['coord']怎么用?Python AbsLine.attrib['coord']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类linetools.spectralline.AbsLine
的用法示例。
在下文中一共展示了AbsLine.attrib['coord']方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: lyman_comp
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['coord'] [as 别名]
def lyman_comp(radec):
# HI Lya, Lyb
lya = AbsLine(1215.670*u.AA, z=2.92939)
lya.limits.set([-300.,300.]*u.km/u.s)
lya.attrib['flag_N'] = 1
lya.attrib['N'] = 1e17 / u.cm**2
lya.attrib['coord'] = radec
lyb = AbsLine(1025.7222*u.AA, z=2.92939)
lyb.limits.set([-300.,300.]*u.km/u.s)
lyb.attrib['coord'] = radec
abscomp = AbsComponent.from_abslines([lya,lyb])
abscomp.synthesize_colm()
return abscomp
示例2: add_DLA
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['coord'] [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()
示例3: fill_lls_lines
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['coord'] [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: test_add_absline
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['coord'] [as 别名]
def test_add_absline():
abscomp,_ = mk_comp('HI', zcomp=0.)
abscomp.add_absline(AbsLine('HI 972'), chk_sep=False, chk_vel=False)
with pytest.raises(ValueError):
abscomp.add_absline(AbsLine('HI 949'), vtoler=-10)
# failed addition
bad_absline = AbsLine('CIV 1550')
bad_absline.limits.set([500, 1000]*u.km/u.s)
bad_absline.attrib['coord'] = SkyCoord(20,20, unit='deg')
abscomp.add_absline(bad_absline)
示例5: test_todict
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['coord'] [as 别名]
def test_todict():
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['coord'] = radec
lyb = AbsLine(1025.7222*u.AA)
lyb.analy['vlim'] = [-300.,300.]*u.km/u.s
lyb.attrib['z'] = lya.attrib['z']
lyb.attrib['coord'] = radec
abscomp = AbsComponent.from_abslines([lya,lyb])
# Instantiate
HIsys = LymanAbsSystem.from_components([abscomp])
# Dict
adict = HIsys.to_dict()
assert isinstance(adict, dict)
# Instantiate
#pdb.set_trace()
newsys = AbsSystem.from_dict(adict)
assert isinstance(newsys, AbsSystem)
示例6: test_todict_withjson
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['coord'] [as 别名]
def test_todict_withjson():
radec = SkyCoord(ra=123.1143*u.deg, dec=-12.4321*u.deg)
# HI Lya, Lyb
lya = AbsLine(1215.670*u.AA)
lya.limits.set([-300.,300.]*u.km/u.s)
lya.attrib['z'] = 2.92939
lya.attrib['coord'] = radec
lyb = AbsLine(1025.7222*u.AA)
lyb.limits.set([-300.,300.]*u.km/u.s)
lyb.attrib['z'] = lya.attrib['z']
lyb.attrib['coord'] = radec
abscomp = AbsComponent.from_abslines([lya,lyb])
# Instantiate
HIsys = LymanAbsSystem.from_components([abscomp])
# Dict
adict = HIsys.to_dict()
assert isinstance(adict, dict)
# Verify it is JSON compatible (failing in Python 3)
import io,json
with io.open('tmp.json', 'w', encoding='utf-8') as f:
f.write(unicode(json.dumps(adict, sort_keys=True, indent=4,
separators=(',', ': '))))
示例7: init_system
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['coord'] [as 别名]
def init_system():
radec = SkyCoord(ra=123.1143*u.deg, dec=-12.4321*u.deg)
# HI Lya, Lyb
lya = AbsLine(1215.670*u.AA, z=2.92939)
lya.limits.set([-300.,300.]*u.km/u.s)
lya.attrib['coord'] = radec
lyb = AbsLine(1025.7222*u.AA, z=lya.z)
lyb.limits.set([-300.,300.]*u.km/u.s)
lyb.attrib['coord'] = radec
abscomp = AbsComponent.from_abslines([lya,lyb])
# SiII
SiIItrans = ['SiII 1260', 'SiII 1304', 'SiII 1526', 'SiII 1808']
abslines = []
for trans in SiIItrans:
iline = AbsLine(trans, z=2.92939)
iline.attrib['coord'] = radec
iline.limits.set([-250.,80.]*u.km/u.s)
abslines.append(iline)
#
SiII_comp = AbsComponent.from_abslines(abslines)
# Instantiate
gensys = GenericAbsSystem.from_components([abscomp,SiII_comp])
return gensys
示例8: si2_comp
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['coord'] [as 别名]
def si2_comp(radec):
# SiII
SiIItrans = ['SiII 1260', 'SiII 1304', 'SiII 1526', 'SiII 1808']
abslines = []
for trans in SiIItrans:
iline = AbsLine(trans, z=2.92939)
iline.attrib['coord'] = radec
iline.limits.set([-250.,80.]*u.km/u.s)
abslines.append(iline)
#
SiII_comp = AbsComponent.from_abslines(abslines)
SiII_comp.logN = 15.
SiII_comp.flag_N = 1
#
return SiII_comp
示例9: oi_comp
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['coord'] [as 别名]
def oi_comp(radec, vlim=[-250.,80.]*u.km/u.s, z=2.92939):
# SiII
OItrans = ['OI 1302']
abslines = []
for trans in OItrans:
iline = AbsLine(trans, z=z, linelist=ism)
iline.attrib['coord'] = radec
iline.limits.set(vlim)
abslines.append(iline)
#
OI_comp = AbsComponent.from_abslines(abslines, skip_synth=True)
OI_comp.logN = 15.
OI_comp.flag_N = 1
#
return OI_comp
示例10: test_rest_limits
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['coord'] [as 别名]
def test_rest_limits():
SiIItrans = ['SiII 1260', 'SiII 1304']
radec = SkyCoord(ra=1., dec=1., unit='deg')
abslines = []
for kk,trans in enumerate(SiIItrans):
iline = AbsLine(trans, z=1., linelist=ism)
iline.attrib['coord'] = radec
if kk == 0:
iline.limits.set([-250.,80.]*u.km/u.s)
else:
iline.limits.set([-50.,180.]*u.km/u.s)
abslines.append(iline)
#
comp = AbsComponent.from_abslines(abslines, chk_vel=False)
comp.reset_limits_from_abslines()
assert np.isclose(comp.vlim[1].value, 180.)
示例11: add_abslines_from_linelist
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['coord'] [as 别名]
def add_abslines_from_linelist(self, llist='ISM', wvlim=None, min_Wr=None, **kwargs):
"""
It adds associated AbsLines satisfying some conditions (see parameters below).
Parameters
----------
llist : str
Name of the linetools.lists.linelist.LineList
object where to look for the transition names.
Default is 'ISM', which means the function looks
within `list = LineList('ISM')`.
wvlims : Quantity array, optional
Observed wavelength limits for AbsLines to be added.
e.g. [1200, 2000]*u.AA.
min_Wr : Quantity, optional
Minimum rest-frame equivalent with for AbsLines to be added.
This is calculated in the very low optical depth regime tau0<<1,
where Wr is independent of Doppler parameter or gamma (see eq. 9.15 of
Draine 2011). Still, a column density attribute for the AbsComponent
is needed.
Returns
-------
Adds AbsLine objects to the AbsComponent._abslines list.
Notes
-----
**kwargs are passed to AbsLine.add_absline() method.
"""
# get the transitions from LineList
llist = LineList(llist)
name = ions.ion_name(self.Zion, nspace=0)
transitions = llist.all_transitions(name)
# unify output to be always QTable
if isinstance(transitions, dict):
transitions = llist.from_dict_to_qtable(transitions)
# check wvlims
if wvlim is not None:
cond = (transitions['wrest']*(1+self.zcomp) >= wvlim[0]) & \
(transitions['wrest']*(1+self.zcomp) <= wvlim[1])
transitions = transitions[cond]
# check outputs
if len(transitions) == 0:
warnings.warn("No transitions satisfying the criteria found. Doing nothing.")
return
# loop over the transitions when more than one found
for transition in transitions:
iline = AbsLine(transition['name'], z=self.zcomp)
iline.limits.set(self.vlim)
iline.attrib['coord'] = self.coord
iline.attrib['logN'] = self.logN
iline.attrib['sig_logN'] = self.sig_logN
iline.attrib['flag_N'] = self.flag_N
iline.attrib['N'] = 10**iline.attrib['logN'] / (u.cm * u.cm)
iline.attrib['sig_N'] = 10**iline.attrib['sig_logN'] / (u.cm * u.cm)
for key in self.attrib.keys():
iline.attrib[key] = self.attrib[key]
if min_Wr is not None:
# check logN is defined
logN = self.logN
if logN == 0:
warnings.warn("AbsComponent does not have logN defined. Appending AbsLines "
"regardless of min_Wr.")
else:
N = 10**logN / (u.cm*u.cm)
Wr_iline = iline.get_Wr_from_N(N=N) # valid for the tau0<<1 regime.
if Wr_iline < min_Wr: # do not append
continue
# add the absline
self.add_absline(iline)
示例12: read_ion_file
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['coord'] [as 别名]
def read_ion_file(ion_fil,lines=None,components=None,linelist=None,toler=0.05*u.AA):
""" Read in JXP-style .ion file in an appropriate manner
NOTE: If program breaks in this function, check the .ion file
to see if it is properly formatted.
If components is passed in, these are filled as applicable.
Parameters
----------
ion_fil : str
Full path to .ion file
lines : list, optional
List of AbsLine objects [used for historical reasons, mainly]
components : list, optional
List of AbsComponent objects
linelist : LineList
May speed up performance
toler : Quantity, optional
Tolerance for matching wrest
"""
assert False # USE LINETOOLS
# Read
names=('wrest', 'logN', 'sig_logN', 'flag_N', 'flg_inst')
table = ascii.read(ion_fil, format='no_header', names=names)
if components is None:
if lines is None:
lines = []
# Generate AbsLine's
for row in table:
# Generate the line
aline = AbsLine(row['wrest']*u.AA, linelist=linelist, closest=True)
# Set z, RA, DEC, etc.
aline.attrib['z'] = self.zabs
aline.attrib['RA'] = self.coord.ra
aline.attrib['Dec'] = self.coord.dec
aline.attrib['coord'] = self.coord
aline.attrib['logN'] = row['logN']
aline.attrib['sig_logN'] = row['sig_logN']
aline.attrib['flag_N'] = row['flag_N']
aline.analy['flg_inst'] = row['flg_inst']
# Check against existing lines
mt = [kk for kk,oline in enumerate(lines) if oline.ismatch(aline)]
if len(mt) > 0:
mt.reverse()
for imt in mt:
print('read_ion_file: Removing line {:g}'.format(lines[imt].wrest))
lines.pop(imt)
# Append
lines.append(aline)
return lines
else: # Fill entries in components
# Generate look-up table for quick searching
all_wv = []
all_idx = []
for jj,comp in enumerate(components):
for kk,iline in enumerate(comp._abslines):
all_wv.append(iline.wrest)
all_idx.append((jj,kk))
all_wv = u.Quantity(all_wv)
# Loop now
for row in table:
mt = np.where(np.abs(all_wv-row['wrest']*u.AA)<toler)[0]
if len(mt) == 0:
pass
elif len(mt) == 1:
# Fill
jj = all_idx[mt[0]][0]
kk = all_idx[mt[0]][1]
components[jj]._abslines[kk].attrib['flag_N'] = row['flag_N']
components[jj]._abslines[kk].attrib['logN'] = row['logN']
components[jj]._abslines[kk].attrib['sig_logN'] = row['sig_logN']
components[jj]._abslines[kk].analy['flg_inst'] = row['flg_inst']
else:
raise ValueError("Matched multiple lines in read_ion_file")
# Return
return table
示例13: add_abslines_from_linelist
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['coord'] [as 别名]
def add_abslines_from_linelist(self, llist='ISM', init_name=None, wvlim=None, min_Wr=None, **kwargs):
"""
It adds associated AbsLines satisfying some conditions (see parameters below).
Parameters
----------
llist : str, optional
Name of the linetools.lists.linelist.LineList
object where to look for the transition names.
Default is 'ISM', which means the function looks
within `list = LineList('ISM')`.
init_name : str, optional
Name of the initial transition used to define the AbsComponent
wvlim : Quantity array, optional
Observed wavelength limits for AbsLines to be added.
e.g. [1200, 2000]*u.AA.
min_Wr : Quantity, optional
Minimum rest-frame equivalent with for AbsLines to be added.
This is calculated in the very low optical depth regime tau0<<1,
where Wr is independent of Doppler parameter or gamma (see eq. 9.15 of
Draine 2011). Still, a column density attribute for the AbsComponent
is needed.
Returns
-------
Adds AbsLine objects to the AbsComponent._abslines list.
Notes
-----
**kwargs are passed to AbsLine.add_absline() method.
"""
from linetools.lists import utils as ltlu
# get the transitions from LineList
llist = LineList(llist)
if init_name is None: # we have to guess it
if (self.Zion) == (-1, -1): # molecules
# init_name must be in self.attrib (this is a patch)
init_name = self.attrib['init_name']
else: # atoms
init_name = ions.ion_to_name(self.Zion, nspace=0)
transitions = llist.all_transitions(init_name)
# unify output to be a Table
if isinstance(transitions, dict):
transitions = ltlu.from_dict_to_table(transitions)
# check wvlims
if wvlim is not None:
# Deal with units
wrest = transitions['wrest'].data * transitions['wrest'].unit
# Logic
cond = (wrest*(1+self.zcomp) >= wvlim[0]) & \
(wrest*(1+self.zcomp) <= wvlim[1])
transitions = transitions[cond]
# check outputs
if len(transitions) == 0:
warnings.warn("No transitions satisfying the criteria found. Doing nothing.")
return
# loop over the transitions when more than one found
for transition in transitions:
iline = AbsLine(transition['name'], z=self.zcomp, linelist=llist)
iline.limits.set(self.vlim)
iline.attrib['coord'] = self.coord
iline.attrib['logN'] = self.logN
iline.attrib['sig_logN'] = self.sig_logN
iline.attrib['flag_N'] = self.flag_N
iline.attrib['N'] = 10**iline.attrib['logN'] / (u.cm * u.cm)
iline.attrib['sig_N'] = 10**iline.attrib['sig_logN'] / (u.cm * u.cm)
for key in self.attrib.keys():
iline.attrib[key] = self.attrib[key]
if min_Wr is not None:
# check logN is defined
if self.logN == 0:
pass
else:
N = 10.**self.logN / u.cm**2
Wr_iline = iline.get_Wr_from_N(N=N) # valid for the tau0<<1 regime.
if Wr_iline < min_Wr: # do not append
continue
# add the absline
self.add_absline(iline)
示例14: load_single_fits
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['coord'] [as 别名]
#.........这里部分代码省略.........
all_Z = []
all_ion = []
for jj in range(summ['NION'][0]):
iont = hdu[3+jj].data
if jj == 0: # Generate new Table
dat_tab = Table(iont)
else:
try:
dat_tab.add_row(Table(iont)[0])
except:
pdb.set_trace()
all_Z.append(iont['ZION'][0][0])
all_ion.append(iont['ZION'][0][1])
# AbsLines
abslines = []
ntrans = len(np.where(iont['LAMBDA'][0] > 1.)[0])
for kk in range(ntrans):
flg = iont['FLG'][0][kk]
# Fill in
aline = AbsLine(iont['LAMBDA'][0][kk]*u.AA, closest=True)
aline.attrib['flag_origCH'] = int(flg)
aline.attrib['EW'] = iont['WOBS'][0][kk]*u.AA/1e3 # Observed
aline.attrib['sig_EW'] = iont['SIGWOBS'][0][kk]*u.AA/1e3
if aline.attrib['EW'] > 3.*aline.attrib['sig_EW']:
aline.attrib['flag_EW'] = 1
else:
aline.attrib['flag_EW'] = 3
# Force an upper limit (i.e. from a blend)
if (flg == 2) or (flg == 4) or (flg == 6):
aline.attrib['flag_EW'] = 3
#
aline.analy['vlim'] = [iont['VMIN'][0][kk],iont['VMAX'][0][kk]]*u.km/u.s
aline.attrib['z'] = igm_sys.zabs
aline.attrib['coord'] = igm_sys.coord
# Check f
if (np.abs(aline.data['f']-iont['FVAL'][0][kk])/aline.data['f']) > 0.001:
Nscl = iont['FVAL'][0][kk] / aline.data['f']
flag_f = True
else:
Nscl = 1.
flag_f = False
# Colm
if ((flg % 2) == 0) or (flg == 15) or (flg == 13):
flgN = 0
print('Skipping column contribution from {:g} as NG for a line; flg={:d}'.format(iont['LAMBDA'][0][kk],flg))
elif (flg == 1) or (flg == 3):
flgN = 1
elif (flg == 5) or (flg == 7):
flgN = 3
elif (flg == 9) or (flg == 11):
flgN = 2
else:
pdb.set_trace()
raise ValueError("Bad flag!")
if flgN == 3:
aline.attrib['logN'] = iont['LOGN2SIG'][0][kk] + np.log10(Nscl)
aline.attrib['sig_logN'] = 9.
elif flgN == 0: # Not for N measurement
pass
else:
aline.attrib['logN'] = iont['LOGN'][0][kk] + np.log10(Nscl)
aline.attrib['sig_logN'] = iont['SIGLOGN'][0][kk]
aline.attrib['flag_N'] = int(flgN)
#pdb.set_trace()
if flgN != 0:
_,_ = ltaa.linear_clm(aline.attrib)