当前位置: 首页>>代码示例>>Python>>正文


Python AbsComponent.attrib[key]方法代码示例

本文整理汇总了Python中linetools.isgm.abscomponent.AbsComponent.attrib[key]方法的典型用法代码示例。如果您正苦于以下问题:Python AbsComponent.attrib[key]方法的具体用法?Python AbsComponent.attrib[key]怎么用?Python AbsComponent.attrib[key]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在linetools.isgm.abscomponent.AbsComponent的用法示例。


在下文中一共展示了AbsComponent.attrib[key]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: complist_from_table

# 需要导入模块: from linetools.isgm.abscomponent import AbsComponent [as 别名]
# 或者: from linetools.isgm.abscomponent.AbsComponent import attrib[key] [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.
           Units for vmin, vmax are assumed km/s if not given
           Units for Ej are assumed cm^-1 if not given

    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
    tkeys = table.keys()

    # mandatory and optional columns
    min_columns = ['RA', 'DEC', 'ion_name', 'z_comp', 'vmin', 'vmax', 'Z', 'ion', 'Ej']
    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))

    # Generate components -- Should add to linetools.isgm.utils
    complist = []
    coords = SkyCoord(ra=table['RA'], dec=table['DEC'], unit='deg')
    for kk,row in enumerate(table):
        # Setup
        if 'flag_logN' in tkeys:
            Ntuple = (row['flag_logN'], row['logN'], row['sig_logN'])
        else:
            Ntuple = None
        # Units
        vmnx = [row['vmin'], row['vmax']]
        vmnx *= u.km/u.s if table['vmin'].unit is None else table['vmin'].unit
        Ej = row['Ej'] * (1/u.cm if table['Ej'].unit is None else table['Ej'].unit)
        #
        abscomp = AbsComponent(coords[kk], (row['Z'], row['ion']),
                               row['z_comp'], vmnx, Ej=Ej, Ntup=Ntuple)
        # Extra attrib
        for key in ['comment', 'name']:
            if key in tkeys:
                setattr(abscomp, key, row[key])
        # Other
        for key in ['sig_z', 'b','sig_b','specfile']:
            try:
                abscomp.attrib[key] = row[key]
            except KeyError:
                pass
            else:
                if table[key].unit is not None:
                    abscomp.attrib[key] *= table[key].unit
                else:
                    if key in ['b', 'sig_b']:
                        warnings.warn("No units for 'b'.  Will assume km/s")
                        abscomp.attrib[key] *= u.km/u.s
        complist.append(abscomp)
    return complist
开发者ID:linetools,项目名称:linetools,代码行数:80,代码来源:utils.py


注:本文中的linetools.isgm.abscomponent.AbsComponent.attrib[key]方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。