Cone search

17 views
Skip to first unread message

Morgan Fouesneau

unread,
Oct 28, 2012, 1:54:45 AM10/28/12
to lsd-...@googlegroups.com
Hi Folks,

I wonder if there is a nice way to do a cone search instead of a box/rectangle selection?

I thought about the filter keyword in fetch with something like

def cone_filter(ra, dec, r, units=['deg', 'deg']):
         def fn(qresult):
                for rows in qresult:
                     _ra   = row['ra']
                     _dec = row['dec']
                     cond = sphdist( ra, dec, _ra, _dec) < r
                     #where sphdist returns the arc length between two points on the unit sphere
                     yield rows[cond]
        return fn

query = db.query('select * from table')
query.fetch( filter=cone_filter(ra,dec,r) )


However this is very not optimal because we are still looking at all the healpix cells. So that it is very inefficient
Is there a better way?

Cheers
Morgan

Branimir Sesar

unread,
Oct 28, 2012, 1:58:48 AM10/28/12
to lsd-...@googlegroups.com
On 10/27/2012 10:54 PM, Morgan Fouesneau wrote:
> Hi Folks,
>
> I wonder if there is a nice way to do a cone search instead of a
> box/rectangle selection?
>
> I thought about the filter keyword in fetch with something like

How about

bounds = [(lsd.bounds.beam(48.91628357, -10.41170942, 10),
lsd.bounds.intervalset((-np.inf, np.inf))]

q.fetch(bounds=bounds)

where "10" means 10 degrees and coordinates are in RA and Dec.

Brani

Morgan Fouesneau

unread,
Oct 28, 2012, 2:01:23 AM10/28/12
to lsd-...@googlegroups.com
Thanks! I did not saw the beam function...

Morgan Fouesneau

unread,
Nov 12, 2012, 2:21:12 PM11/12/12
to lsd-...@googlegroups.com
Hi, I am trying to use bounds during the fetch but I have this strange error that I do not understand. It seems to work for a while and then crashed.
The error does not show up using lsd-query script.

1 : import lsd
2 : db = lsd.DB('lsd-test/')
3 : q = db.query ('select phat_id, ra,dec, brick from phatphot')
4 : b = [lsd.bounds.rectangle(120,20,160,60), None]
5 : q.fetch(bounds)
6 : q.fetch(b)

Remote Traceback (most recent call last):
  File "/home/morgan/bin/lsd/opt/lsd/current/lib/python/lsd/pool2.py", line 81, in _worker
    for result in mapper(item, *mapper_args):
  File "/home/morgan/bin/lsd/opt/lsd/current/lib/python/lsd/table_catalog.py", line 90, in _get_cells_kernel
    for bounds_xy, bounds_t in bounds:
ValueError: need more than 1 value to unpack

Any Idea of what I do wrong?

Morgan Fouesneau

unread,
Nov 12, 2012, 2:29:41 PM11/12/12
to lsd-...@googlegroups.com
Nevermind, for people who did the same mistake:

b = [lsd.bounds.rectangle(120,20,160,60), None]
q.fetch( [ b ] )


On Monday, November 12, 2012 11:21:13 AM UTC-8, Morgan Fouesneau wrote:
Hi, I am trying to use bounds during the fetch but I have this strange error that I do not understand. It seems to work for a while and then crashed.
The error does not show up using lsd-query script.

1 : import lsd
2 : db = lsd.DB('lsd-test/')
3 : q = db.query ('select phat_id, ra,dec, brick from phatphot')
4 : b = [lsd.bounds.rectangle(120,20,160,60), None]
5 : q.fetch(bounds)


Eddie Schlafly

unread,
Nov 12, 2012, 3:43:35 PM11/12/12
to lsd-...@googlegroups.com
Yup. There is also bounds.make_canonical() for this.

e.g., q.fetch(bounds.make_canonical(bounds.rectangle(...))
I think that also handles the reverse situation, where you have only
specified a time range.
Reply all
Reply to author
Forward
0 new messages