[AstroPy] Selecting data from ascii.table with multiple conditions

Aldcroft, Thomas aldcroft at head.cfa.harvard.edu
Thu Oct 24 22:32:09 EDT 2013


On Thu, Oct 24, 2013 at 4:54 PM, Joe Philip Ninan <indiajoe at gmail.com>wrote:

> Hi,
> I wanted to pick out certain data from an ascii table based on conditions
> on other columns, i was using the following way.
>
> For example, Mytable is an ascii.table loaded from Daophot output file.
> To extract the MAG of stars with ID > 60 and MAG>18,
> Following is the command which works, i had to come up with.
>
> Mytable[np.where((Mytable['ID']>60).data &
> (Mytable['MAG']>18).data)]['MAG'].data.data
>
> Quite a lot of ".data" to be appended !!
> Am i missing some feature astropy already has for doing these kind of data
> selection from table?
>

Here's an example showing a more concise way to do this using boolean
masks.  In general you should not ever be using the .data attribute of
Columns.

In [2]: from astropy.table import Table
In [3]: import numpy as np
In [4]: t = Table([np.arange(10), np.arange(10)], names=('a', 'b'))
In [5]: mask = (t['a'] > 4) & (t['b'] < 8)
In [6]: t2 = t[mask]
In [7]: print t2
 a   b
--- ---
  5   5
  6   6
  7   7

Cheers,
Tom


>
> I didn't find any example for these kind of usage in the doc
> http://docs.astropy.org/en/latest/io/ascii/index.html
> May be we should add one.
>
> Thanks,
> -cheers
> joe
>
>
> --
> /---------------------------------------------------------------
> "GNU/Linux: because a PC is a terrible thing to waste" -  GNU Generation
>
> ************************************************
> Joe Philip Ninan    http://sites.google.com/site/jpninan/
> Research Scholar        /________________\
> DAA,                            | Vadakeparambil |
> TIFR,                           | Pullad P.O.         |
> Mumbai-05, India.      | Kerala, India      |
> Ph: +917738438212   | PIN:689548       |
> ------------------------------\_______________/--------------
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> http://mail.scipy.org/mailman/listinfo/astropy
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20131024/97b371b8/attachment.html>


More information about the AstroPy mailing list