如何在天文表中索引可观察的坐标 [英] How to index observable coordinates in an astropy Table

查看:153
本文介绍了如何在天文表中索引可观察的坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我问了这个问题(



我想删除与小于-10度的磁偏角相对应的行,类似于我在第一个问题中要求这样做的方式,但也要从表格中删除整行数据,而不仅仅是 radecs值。



我发现了

很抱歉,我问过您另一个问题。我认为您可能已将坐标保存在一个列中,而不是在其他列中。



如果它们在不同列中,则其工作原理与其他答案完全相同(但您必须更改索引的位置),因为您需要索引列而不是属性:

  x = Table(...)
x1 = x [x ['Dec']> -10 * u.degree]#删除-10度以下的所有值
x2 = x [x ['Apparent Magnitude']< 20]#删除每一个大于20的恒星

so x ['表观幅度'] 为列表观幅度 等。



此外:您还可以指定更复杂的条件:

  magnitude_below_20 = x ['Apparent Magnitude']< 20 
dec_above_m10 = x [’Dec’]> -10 * u.degree
#获取同时满足两个条件的每一行:
x_from_comb_condition = x [magnitude_below_20& dec_above_m10]
#或使用numpy-ufunc(给出相同的结果):
x_from_comb_condition = x [np.logical_and(magnitude_below_20,dec_above_m10)]

或是否适用一项条件( | np.logical_or )或该条件不适用( np.logical_not






例如:

 来自astropy。协调从astropy.table导入的SkyCoord 
导入表
导入astropy.units为u
导入numpy为np
phi = np.linspace(0,2 * np.pi,20 )
theta = np.linspace(0,np.pi,20)
radecs = SkyCoord(ra = phi * u.rad,dec =(0.5 * np.pi-theta)* u.rad )
app_mag = np.random.uniform(15,25,20)
x = Table([radecs.ra,radecs.dec,app_mag],names =('RA','Dec','表观幅度'))
x [x ['Dec']> -10 * u.degree]

给我:

  RA 12月视在幅度
deg deg
float64 float64 float64
0.0 90.0 20.1080708665
18.9473684211 80.5263157895 22.7223534546
37.8947368421 71.0526315789 19.4416167208
56.8421052632 61.5789473684 20.7207435685
75.7894736842 52.1052631579 19.9318711443
94.7368421053 42.6315789474 23.8544483535
113.684210526 33.1578947368 15.8981196334

132.631578947 4.1.52475475472.475654752.4758.24754.54752 15.47234563 475.125.125.475.125.475.125.475.475.65
189.473684211 -4.73684210526 24.194771397

而完整的是:

  RA 12月表观幅度
deg deg
float64 float64 float64
0.0 90.0 20.1080708665
18.9473684211 80.5263157895 22.7223534546
37.8947368421 71.0526315789 19.4416167208
56.8421052632 61.5789473684 20.7207435685
75.7894736842 52.1052631579 19.9318711443

94.7368421053 23.16754947 524.13654984 524.115.4578 23.6842105263 24.2866475431
151.578947368 14.2105263158 15.9503148326
170.526315789 4.73684210526 16.5505303858
189.473684211 -4.73684210526 24.194771397
208.421052632 -14.2105263263158 15.4721094564
2b 223.1684105738474 $ 608 $ b 265.263157895 -42.6315789474 17.3627571053
284.210526316 -52.1052631579 22.7065806097
303.157894737 -61.5789473684 23.7244993197
322.105263158 -71.0526315789 19.7676029836
341.052631579 -80.5263157895 19.5025214878

因此,这仅保留满足条件的行,并忽略所有其他行。 / p>




可以手动删除行(如果您知道行号):

  x.remove_row(0)#删除第一行
x.remove_row(-1)#删除最后一行

但是,如果您由于条件而希望放弃行,通常需要使用索引。 remove_row 更多用于手动删除一两行。也许是因为它们是误报之类的东西……
他们就地工作。所以永远不要 x = x.remove_row(-1),因为这样 x 将是 None


I asked this question (How to sort through a list of observable coordinates?) yesterday about sorting a list of coordinates to remove certain values below a threshold, I got a great answer from @MSeifert but I have a table in which these coordinate values are matched up with other properties of the targets (e.g. apparent magnitude and Alt/Az coordinates), so what I am asking for now is a way to do this masking technique in an astropy.table rather than an astropy.coordinates.SkyCoord list from my previous question.

Let me outline the problem:

I obtain my initial RA & Dec coordinates using this line:

radecs = astropy.coordinates.SkyCoord(ra=phi*u.rad, dec=(0.5*np.pi - theta)*u.rad)

Then I convert this to a Table:

x=Table([radecs.ra,radecs.dec,altaz.alt,altaz.az,app_mag], names=('RA', 
'Dec','Altitude', 'Azimuth','Apparent Magnitude'))

Ignoring the magnitude column it then looks like this:

I would like to remove the rows that correspond to a declination less than -10 degrees, similar to how I asked to do this in my first question, but to also remove the whole row of data from the Table, not just the 'radecs' values.

I found this question online which suggsts to me that the function for removing rows from Tables doesnt exists (at least in June 2013), but I think there should be a fairly simple solution to my problem.

解决方案

I'm sorry I asked you to ask another question. I thought you may have saved the coordinates in one column rather than in different columns.

If they are in different columns it works exactly like in the other answer (but you must change the indexing a bit) because you need to index columns rather than attributes:

x=Table(...)
x1 = x[x['Dec'] > -10*u.degree] # Remove everything below -10degree declination
x2 = x[x['Apparent Magnitude'] < 20] # Remove every star with a magnitude above 20

so x['Apparent Magnitude'] gives you the column 'Apparent Magnitude' and so on.

Besides: You could also specify more complex conditions:

magnitude_below_20 = x['Apparent Magnitude'] < 20
dec_above_m10 = x['Dec'] > -10*u.degree
# Get every row that satisfies both conditions:
x_from_comb_condition = x[magnitude_below_20 & dec_above_m10]
# or using the numpy-ufunc (gives the same result):
x_from_comb_condition = x[np.logical_and(magnitude_below_20, dec_above_m10)]

or if one condition applies (| or np.logical_or) or if the condition does not apply (~ or np.logical_not)


For example:

from astropy.coordinates import SkyCoord
from astropy.table import Table
import astropy.units as u
import numpy as np
phi = np.linspace(0,2*np.pi,20)
theta = np.linspace(0, np.pi, 20)
radecs = SkyCoord(ra=phi*u.rad, dec=(0.5*np.pi - theta)*u.rad)
app_mag = np.random.uniform(15,25, 20)
x=Table([radecs.ra,radecs.dec,app_mag], names=('RA', 'Dec','Apparent Magnitude'))
x[x['Dec'] > -10*u.degree]

gives me:

RA              Dec             Apparent Magnitude
deg             deg 
float64         float64         float64
0.0             90.0            20.1080708665
18.9473684211   80.5263157895   22.7223534546
37.8947368421   71.0526315789   19.4416167208
56.8421052632   61.5789473684   20.7207435685
75.7894736842   52.1052631579   19.9318711443
94.7368421053   42.6315789474   23.8544483535
113.684210526   33.1578947368   15.8981196334
132.631578947   23.6842105263   24.2866475431
151.578947368   14.2105263158   15.9503148326
170.526315789   4.73684210526   16.5505303858
189.473684211   -4.73684210526  24.194771397

whereas the complete Table was:

RA              Dec             Apparent Magnitude
deg             deg 
float64         float64         float64
0.0             90.0            20.1080708665
18.9473684211   80.5263157895   22.7223534546
37.8947368421   71.0526315789   19.4416167208
56.8421052632   61.5789473684   20.7207435685
75.7894736842   52.1052631579   19.9318711443
94.7368421053   42.6315789474   23.8544483535
113.684210526   33.1578947368   15.8981196334
132.631578947   23.6842105263   24.2866475431
151.578947368   14.2105263158   15.9503148326
170.526315789   4.73684210526   16.5505303858
189.473684211   -4.73684210526  24.194771397
208.421052632   -14.2105263158  15.4721094564
227.368421053   -23.6842105263  20.6082525987
246.315789474   -33.1578947368  21.9730819638
265.263157895   -42.6315789474  17.3627571053
284.210526316   -52.1052631579  22.7065806097
303.157894737   -61.5789473684  23.7244993197
322.105263158   -71.0526315789  19.7676029836
341.052631579   -80.5263157895  19.2663871267
0.0             -90.0           19.5025214878

so this kept only the rows where the condition was met and "ignored" all the others.


Removing rows manually (if you know the row number) is possible:

x.remove_row(0) # Removes the first row
x.remove_row(-1) # Removes the last row

But normally indexing is what you want if you want to discard rows because of conditions. The remove_row is more for deleting one/two rows manually. Maybe because they were false positives or something else... And they work in-place. So never do x = x.remove_row(-1) because then x will be None.

这篇关于如何在天文表中索引可观察的坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆