我有一个astropy
表,如下所示:
$ print(astro_table)
id xcentroid ycentroid sharpness roundness1 ... npix sky peak flux mag
---- ------------- ------------- -------------- ----------------- ... ---- --- ------------- ------------- -----------------
6603 346.836613078 4089.22051381 0.292000724835 0.0734556783249 ... 49.0 0.0 69302.3984375 245.224909511 -5.97391145737
6177 919.415933548 3859.57301712 0.406784343306 -0.277953216167 ... 49.0 0.0 68524.5234375 220.268294418 -5.85737997245
6602 345.532899395 4088.87923557 0.401278628932 -0.450002792676 ... 49.0 0.0 70189.1953125 210.018583984 -5.80564431499
... ... ... ... ... ... ... ... ... ... ...
5626 3095.76998822 3522.08198969 0.393572474564 -0.543965319616 ... 49.0 0.0 3037.37036133 1.00374231333 -0.00405558116745
3577 824.59454487 2245.85801066 0.578026446726 -0.00166964746818 ... 49.0 0.0 3150.42285156 1.00347471149 -0.00376608082606
612 3971.99991783 391.836698859 0.363131852861 -0.0206680542966 ... 49.0 0.0 3087.11572266 1.00319616544 -0.00346465867044
Length = 6603 rows
我想创建一个新表格,过滤掉peak
值超过某个p_max
阈值的所有明星。
我正在玩filter方法,这就是我能想到的:
def not_saturated(table, key_colnames):
"""Filter out saturated stars"""
if table['peak'] < 60000.:
return True
return False
# 'sources' is the Astropy table, generated previously by the code.
# Group the table by 'id' column.
tg = sources.group_by('id')
# Apply filter.
sour_peak_filt = tg.groups.filter(not_saturated)
这样可行,但感觉不必要的错综复杂。另外,我想将p_max
参数传递给non_saturated()
函数,但我不能,因为它只需要两个参数。这迫使我对函数(60000.
)中的值进行硬编码,这是我不想做的。
答案 0 :(得分:2)
正如我的评论所述,此答案基于selecting records from a table的信息。我使用了astropy发行版中提供的匹配文件。
2016-11-09T19:10:32.544099+00:00 app[web.1]: [6df3c971-b288-4b7e-893e-dcea2f2ef537] ActionView::Template::Error (missing required :bucket option):
2016-11-09T19:10:32.544249+00:00 app[web.1]: [6df3c971-b288-4b7e-893e-dcea2f2ef537] 15: <tbody>
2016-11-09T19:10:32.544275+00:00 app[web.1]: [6df3c971-b288-4b7e-893e-dcea2f2ef537] 16: <% @pins.each do |pin| %>
2016-11-09T19:10:32.544676+00:00 app[web.1]: [6df3c971-b288-4b7e-893e-dcea2f2ef537] 17: <tr>
2016-11-09T19:10:32.544707+00:00 app[web.1]: [6df3c971-b288-4b7e-893e-dcea2f2ef537] 18: <td><%= image_tag pin.image.url %></td>
2016-11-09T19:10:32.544734+00:00 app[web.1]: [6df3c971-b288-4b7e-893e-dcea2f2ef537] 19: <td><%= pin.description %></td>
2016-11-09T19:10:32.544764+00:00 app[web.1]: [6df3c971-b288-4b7e-893e-dcea2f2ef537] 20: <td><%= pin.user.email if pin.user %></td>
2016-11-09T19:10:32.544790+00:00 app[web.1]: [6df3c971-b288-4b7e-893e-dcea2f2ef537] 21: <td><%= link_to 'Show', pin %></td>
2016-11-09T19:10:32.544818+00:00 app[web.1]: [6df3c971-b288-4b7e-893e-dcea2f2ef537]
2016-11-09T19:10:32.544854+00:00 app[web.1]: [6df3c971-b288-4b7e-893e-dcea2f2ef537] app/views/pins/index.html.erb:18:in `block in _app_views_pins_index_html_erb___1097567776692289569_70248207788000'
2016-11-09T19:10:32.544884+00:00 app[web.1]: [6df3c971-b288-4b7e-893e-dcea2f2ef537] app/views/pins/index.html.erb:16:in `_app_views_pins_index_html_erb___1097567776692289569_70248207788000'