本文整理汇总了Python中linetools.spectralline.AbsLine.attrib['sig_logN']方法的典型用法代码示例。如果您正苦于以下问题:Python AbsLine.attrib['sig_logN']方法的具体用法?Python AbsLine.attrib['sig_logN']怎么用?Python AbsLine.attrib['sig_logN']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类linetools.spectralline.AbsLine
的用法示例。
在下文中一共展示了AbsLine.attrib['sig_logN']方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mk_comp
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['sig_logN'] [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
示例2: abslines_from_VPfile
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['sig_logN'] [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
示例3: add_abslines_from_linelist
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['sig_logN'] [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)
示例4: read_ion_file
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['sig_logN'] [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
示例5: jenkins2005
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['sig_logN'] [as 别名]
def jenkins2005():
"""Jenkins, E. et al. 2005, ApJ, 2005, 623, 767
PHL 1811
HST/STIS, FUSE
Metals parsed from Table 1
OI taken from text
Had to input error on columns by hand (JXP)
Total NHI from Lyman series. see Fig 3
M/H from O/H
"""
# Grab ASCII file from ApJ
tab_fil = pyigm_path+"/data/LLS/Literature/jenkins2005.tb1.ascii"
chk_fil = glob.glob(tab_fil)
if len(chk_fil) > 0:
tab_fil = chk_fil[0]
else:
url = 'http://iopscience.iop.org/0004-637X/623/2/767/fulltext/61520.tb1.txt'
print('LLSSurvey: Grabbing table file from {:s}'.format(url))
f = urllib2.urlopen(url)
with open(tab_fil, "wb") as code:
code.write(f.read())
# Setup
radec = '215501.5152-092224.688' # SIMBAD
lls = LLSSystem(name='PHL1811_z0.081', radec=radec, zem=0.192,
zabs=0.080923, vlim=[-100., 100.]*u.km/u.s, NHI=17.98, ZH=-0.19,
sig_NHI=np.array([0.05,0.05]))
lls.lines = [] # Probably not used
# AbsLines
ism = LineList('ISM')
Nsig = {'C IV': 0.4, 'N II': 0.4, 'Si II': 0.05, 'Si IV': 0.25,
'S II': 0.2, 'Fe II': 0.12, 'H I': 0.05, 'S III': 0.06}
# Parse Table
with open(tab_fil,'r') as f:
flines = f.readlines()
ion_dict = {}
for iline in flines:
iline = iline.strip()
if (len(iline) == 0):
continue
# Split on tabs
isplit = iline.split('\t')
# Offset?
ioff = 0
if isplit[0][0] in ['1','2']:
ioff = -1
# Catch bad lines
if (isplit[1+ioff][0:6] in ['1442.0','1443.7','1120.9']): # Skip goofy CII line and CII*
continue
if len(isplit[2+ioff]) == 0:
continue
# Ion
if (len(isplit[0].strip()) > 0) & (isplit[0][0] not in ['1','2']):
ionc = isplit[0].strip()
try:
Zion = ltai.name_ion(ionc)
except KeyError:
pdb.set_trace()
# Generate the Line
try:
newline = AbsLine(float(isplit[2+ioff])*u.AA,linelist=ism, closest=True)
except ValueError:
pdb.set_trace()
newline.attrib['z'] = lls.zabs
# Spectrum
newline.analy['datafile'] = 'STIS' if 'S' in isplit[1] else 'FUSE'
# EW
try:
EWvals = isplit[4+ioff].split(' ')
except IndexError:
pdb.set_trace()
newline.attrib['EW'] = float(EWvals[0])*u.AA/1e3
newline.attrib['sig_EW'] = float(EWvals[2])*u.AA/1e3
newline.attrib['flag_EW'] = 1
if len(isplit) < (5+ioff+1):
continue
# Colm?
#xdb.set_trace()
newline.attrib['sig_logN'] = 0.
if (len(isplit[5+ioff].strip()) > 0) & (isplit[5+ioff].strip() != '\\ldots'):
if isplit[5+ioff][0] == '\\':
ipos = isplit[5+ioff].find(' ')
newline.attrib['logN'] = float(isplit[5+ioff][ipos+1:])
newline.attrib['flag_N'] = 2
elif isplit[5+ioff][0] == '<':
ipos = 0
newline.attrib['logN'] = float(isplit[5+ioff][ipos+1:])
newline.attrib['flag_N'] = 3
elif isplit[5+ioff][0] == '1':
try:
newline.attrib['logN'] = float(isplit[5+ioff][0:5])
except ValueError:
pdb.set_trace()
newline.attrib['flag_N'] = 1
try:
newline.attrib['sig_logN'] = Nsig[ionc]
except KeyError:
print('No error for {:s}'.format(ionc))
else:
#.........这里部分代码省略.........
示例6: add_abslines_from_linelist
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['sig_logN'] [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)
示例7: load_single_fits
# 需要导入模块: from linetools.spectralline import AbsLine [as 别名]
# 或者: from linetools.spectralline.AbsLine import attrib['sig_logN'] [as 别名]
#.........这里部分代码省略.........
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)
# Append
abslines.append(aline)
# Component
if len(abslines) == 0:
comp = AbsComponent(cgabs.igm_sys.coord,
(iont['ZION'][0][0],iont['ZION'][0][1]),
igm_sys.zabs, igm_sys.vlim)
else:
comp = AbsComponent.from_abslines(abslines, chk_vel=False)
if comp.Zion != (1,1):
comp.synthesize_colm() # Combine the abs lines
if np.abs(comp.logN - float(iont['CLM'][0])) > 0.15:
print("New colm for ({:d},{:d}) and sys {:s} is {:g} different from old".format(
comp.Zion[0], comp.Zion[1], cgabs.name, comp.logN - float(iont['CLM'][0])))
if comp.flag_N != iont['FLG_CLM'][0]:
if comp.flag_N == 0:
pass
else:
print("New flag for ({:d},{:d}) and sys {:s} is different from old".format(
comp.Zion[0], comp.Zion[1], cgabs.name))
pdb.set_trace()
#_,_ = ltaa.linear_clm(comp)
cgabs.igm_sys.add_component(comp)
self.cgm_abs.append(cgabs)
# Add Z,ion
dat_tab.add_column(Column(all_Z,name='Z'))
dat_tab.add_column(Column(all_ion,name='ion'))
# Rename
dat_tab.rename_column('LOGN','indiv_logN')
dat_tab.rename_column('SIGLOGN','indiv_sig_logN')
dat_tab.rename_column('CLM','logN')
dat_tab.rename_column('SIG_CLM','sig_logN')
dat_tab.rename_column('FLG_CLM','flag_N')
# Set
self.cgm_abs[-1].igm_sys._ionN = dat_tab
# NHI
HI = (dat_tab['Z'] == 1) & (dat_tab['ion'] == 1)
if np.sum(HI) > 0:
self.cgm_abs[-1].igm_sys.NHI = dat_tab[HI]['logN'][0]
self.cgm_abs[-1].igm_sys.sig_NHI = dat_tab[HI]['sig_logN'][0]
self.cgm_abs[-1].igm_sys.flag_NHI = dat_tab[HI]['flag_N'][0]
else:
warnings.warn("No HI measurement for {}".format(self.cgm_abs[-1]))
self.cgm_abs[-1].igm_sys.flag_NHI = 0