本文整理汇总了Python中linetools.isgm.abscomponent.AbsComponent.attrib[colname]方法的典型用法代码示例。如果您正苦于以下问题:Python AbsComponent.attrib[colname]方法的具体用法?Python AbsComponent.attrib[colname]怎么用?Python AbsComponent.attrib[colname]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类linetools.isgm.abscomponent.AbsComponent
的用法示例。
在下文中一共展示了AbsComponent.attrib[colname]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: complist_from_table
# 需要导入模块: from linetools.isgm.abscomponent import AbsComponent [as 别名]
# 或者: from linetools.isgm.abscomponent.AbsComponent import attrib[colname] [as 别名]
def complist_from_table(table):
"""
Returns a list of AbsComponents from an input astropy.Table.
Parameters
----------
table : Table
Table with component information (each row must correspond
to a component). Each column is expecting a unit when
appropriate.
Returns
-------
complist : list
List of AbsComponents defined from the input table.
Notes
-----
Mandatory column names: 'RA', 'DEC', 'ion_name', 'z_comp', 'vmin', 'vmax'
These column are required.
Special column names: 'name', 'comment', 'logN', 'sig_logN', 'flag_logN'
These columns will fill internal attributes when corresponding.
In order to fill in the Ntuple attribute all three 'logN', 'sig_logN', 'flag_logN'
must be present. For convenience 'logN' and 'sig_logN' are expected to be floats
corresponding to their values in np.log10(1/cm^2).
Other columns: 'any_column_name'
These will be added as attributes within the AbsComponent.attrib dictionary,
with their respective units if given.
"""
# Convert to QTable to handle units in individual entries more easily
table = QTable(table)
# mandatory and optional columns
min_columns = ['RA', 'DEC', 'ion_name', 'z_comp', 'vmin', 'vmax']
special_columns = ['name', 'comment', 'logN', 'sig_logN', 'flag_logN']
for colname in min_columns:
if colname not in table.keys():
raise IOError('{} is a mandatory column. Please make sure your input table has it.'.format(colname))
#loop over rows
complist = []
for row in table:
# mandatory
coord = SkyCoord(row['RA'].to('deg').value, row['DEC'].to('deg').value, unit='deg') # RA y DEC must both come with units
Zion = name_to_ion(row['ion_name'])
zcomp = row['z_comp']
vlim =[row['vmin'].to('km/s').value, row['vmax'].to('km/s').value] * u.km / u.s # units are expected here too
# special columns
try:
Ntuple = (row['flag_logN'], row['logN'], row['sig_logN']) # no units expected
except KeyError:
Ntuple = None
try:
comment = row['comment']
except KeyError:
comment = ''
try:
name = row['name']
except KeyError:
name = None
# define the component
comp = AbsComponent(coord, Zion, zcomp, vlim, Ntup=Ntuple, comment=comment, name=name)
# other columns will be filled in comp.attrib dict
for colname in table.keys():
if (colname not in special_columns) and (colname not in min_columns):
kms_cols = ['b', 'sig_b']
if colname in kms_cols: # check units for parameters expected in velocity units
try:
val_aux = row[colname].to('km/s').value * u.km / u.s
except u.UnitConversionError:
raise IOError('If `{}` column is present, it must have velocity units.'.format(colname))
comp.attrib[colname] = val_aux
# parameters we do not care about units much
else:
comp.attrib[colname] = row[colname]
# append
complist += [comp]
return complist