astropy / astropy-healpix

BSD-licensed HEALPix for Astropy - maintained by @astrofrog and @lpsinger
https://astropy-healpix.readthedocs.io
BSD 3-Clause "New" or "Revised" License
52 stars 22 forks source link

Add polygon query #100

Open cdeil opened 6 years ago

cdeil commented 6 years ago

A big feature astropy.healpix that we're still missing is polygon query.

The algorithm used in the C++ lib for HEALPix polygon query (and also disk query) is outlined in http://adsabs.harvard.edu/abs/2015A&A...580A.132R . In healpy it's exposed like this: healpy.query_polygon

For both polygon and disk query, efficient options to return the result is range sets (see the paper mentioned above), or MOCs (see https://github.com/cds-astro/mocpy) (cc @tboch). Another question is how to avoid duplication with astropy-regions which already has a polygon class with contains implemented (although at the moment only for cartesian, not spherical polygons, but that should be added there).

In this package I see that @dstndstn put a point_in_polygon, but I don't think HEALPix query_polygon exists, only disk query. @dstndstn - Is that correct, or do you have code for this somewhere already?

@tboch also mentioned that some use cases require to know whether a given pixel is entirely or partially covered is needed; info that currently isn't available by our cone_search API.

dstndstn commented 6 years ago

Correct, I only have disk query for healpixes

astrofrog commented 6 years ago

One option to get something working reasonably quickly and avoid duplication with regions would be to first do a disk query, then pass the resulting indices through a spherical polygon region (in the regions package, indeed needing implementing).

Note that in regions we'd probably use spherical-geometry to do the actual contain test, and spherical-geometry is C code, so it's possible we could make use of that directly here in the C code for optimal performance.

cdeil commented 6 years ago

Yesterday at the Python-HEALPix-workshop @fxpineau mentioned that he has developed a high-performance HEALPix Java lib that includes disk and polygon query. It might become available later this year, maybe under a BSD or compatible license. So IMO one option is that we just wait for that and then translate the query methods to C and use them for astropy-healpix.

Of course, if someone has the time or expertise to implement polygon query e.g. based on the description in http://adsabs.harvard.edu/abs/2015A&A...580A.132R now, great! But for me, given that it is really non-trivial to implement and get it right for the various cases that arise for different polygon shapes and regions on the sphere, I don't plan to take on this task now.