如何在天文表中索引可观察的坐标 [英] How to index observable coordinates in an astropy Table
问题描述
我问了这个问题(
我想删除与小于-10度的磁偏角相对应的行,类似于我在第一个问题中要求这样做的方式,但也要从表格中删除整行数据,而不仅仅是 radecs值。
我发现了 很抱歉,我问过您另一个问题。我认为您可能已将坐标保存在一个列中,而不是在其他列中。 如果它们在不同列中,则其工作原理与其他答案完全相同(但您必须更改索引的位置),因为您需要索引列而不是属性: so 此外:您还可以指定更复杂的条件: 或是否适用一项条件( 例如: 给我: 而完整的 因此,这仅保留满足条件的行,并忽略所有其他行。 / p> 可以手动删除行(如果您知道行号): 但是,如果您由于条件而希望放弃行,通常需要使用索引。 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 Let me outline the problem: I obtain my initial RA & Dec coordinates using this line: Then I convert this to a 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: so Besides: You could also specify more complex conditions: or if one condition applies ( For example: gives me: whereas the complete 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: But normally indexing is what you want if you want to discard rows because of conditions. The 这篇关于如何在天文表中索引可观察的坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
x = Table(...)
x1 = x [x ['Dec']> -10 * u.degree]#删除-10度以下的所有值
x2 = x [x ['Apparent Magnitude']< 20]#删除每一个大于20的恒星
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
x.remove_row(0)#删除第一行
x.remove_row(-1)#删除最后一行
remove_row
更多用于手动删除一两行。也许是因为它们是误报之类的东西……
他们就地工作。所以永远不要 x = x.remove_row(-1)
,因为这样 x
将是 None
。astropy.table
rather than an astropy.coordinates.SkyCoord
list from my previous question.radecs = astropy.coordinates.SkyCoord(ra=phi*u.rad, dec=(0.5*np.pi - theta)*u.rad)
Table
:x=Table([radecs.ra,radecs.dec,altaz.alt,altaz.az,app_mag], names=('RA',
'Dec','Altitude', 'Azimuth','Apparent Magnitude'))
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
x['Apparent Magnitude']
gives you the column 'Apparent Magnitude'
and so on.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 np.logical_or
) or if the condition does not apply (~
or np.logical_not
)
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]
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
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
x.remove_row(0) # Removes the first row
x.remove_row(-1) # Removes the last row
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
.