【问题标题】:Selecting a subset of an astropy table选择一个天文表的子集
【发布时间】:2020-02-28 23:34:52
【问题描述】:

我正在尝试创建一个 astropy 表的子集。

我被告知我需要使用 numpy,但是当我通过 numpy 访问表时,我似乎没有得到 2d numpy 表并且很困惑。

我试图创建子集的表来自 GAMA 调查

我试过了

import numpy as np
from astropy.table import Table
t = Table.read('GAMA_Data/InputCatA.fits')
ta = np.array(t)

我希望执行一些子集,例如

t['PETROMAG_I'] > 17.5)

我收到了一些建议,我需要使用 numpy。 我可以确定“PETROMG_I”是第 16 列

print(t.colnames.index('PETROMAG_I'))

但看不到如何在表或 numpy 数组上做子集

 print('Source Table : '+str(len(ta)))
 print('Shape : '+str(ta.shape))
 print(ta)

Source Table : 960510
Shape : (960510,)
[(     0, 588848900971299297, 145.46972201, 0.65141891,           68987912448,        0, 3.0191224, 20.57372 , 20.748629, 4503874773745664, 0.3678997 , 2.9388053, 1.2919843 , 28.094984, 21.347776, 19.99194 , 19.40016 , 18.74607 , 22.722446, 21.583874, 19.939884, 19.270464, 18.782948,  9843, 756)
 (     1, 588848900971299302, 145.47892146, 0.63515137,       68987912448,        0, 3.3755734, 21.073107, 21.055092, 4503874773745664, 0.37012857, 3.619758 , 1.5749472 , 21.076248, 20.432001, 20.08754 , 19.929377, 20.802927, 21.622843, 20.553198, 20.045462, 19.874853, 19.653866,  9843, 756)

【问题讨论】:

    标签: python astropy


    【解决方案1】:

    用途:

    mask = t['PETROMAG_I'] > 17.5  # Makes a boolean selection mask (numpy array)
    t_new = t[mask]  # Makes a new astropy Table
    

    这将为您提供一个包含选定行的 astropy 表。这记录在该部分底部附近的示例中:https://docs.astropy.org/en/stable/table/access_table.html#accessing-data

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多