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


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

本文整理汇总了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
开发者ID:lwymarie,项目名称:linetools,代码行数:86,代码来源:utils.py


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