[AstroPy] SQL-like queries against astropy.table objects
Brian Kloppenborg
bkloppenborg at gmail.com
Fri Feb 7 23:22:55 EST 2014
Greetings,
I have unfortunately fallen quite far behind on astropy development and
my knowledge of the finer features of many of Python's libraries is
limited because I do most of my work in C/C++.
I have a use case in which I have a small (< 100k row) amount of static
data which I need to both visualize and be able to easily manipulate
(grouping, inclusion/exclusion based upon some criteria, application of
some simple mathematics without altering the original data). I've used
SQL extensively in the past and the queries which I would run are a
perfect use case; however, visualizing the data with matplotlib (or
similar) might be more efficiently accomplished from an astropy.table
object. Is it possible to run an SQL-like query against an astropy.table
object? If not with SQL-like syntax, how else could this be done?
For example, say I have a table with the following columns (not the use
case, but an easy demo):
JD, mag, mag_error
I could find all data points with an SNR > 100 within a date range by:
SELECT * from table WHERE (JD > value AND JD < value AND
mag/mag_err > 100);
quite quickly. Conversely, implementing something similar using numpy
operations appears to be quite painful (e.g.
http://stackoverflow.com/questions/7169240/moving-large-sql-query-to-numpy)
unless this is already built-in to astropy.table objects.
Kind regards,
Brian Kloppenborg
More information about the AstroPy
mailing list