added healpix order argument to the cone search api
This commit is contained in:
parent
fae86166e4
commit
77ae33a1e8
27
views.py
27
views.py
@ -9,7 +9,8 @@ from .serializers import GaiaSourceSerializer
|
||||
from drf_spectacular.utils import extend_schema, OpenApiResponse, OpenApiParameter
|
||||
|
||||
import numpy as np
|
||||
import healpy as hp
|
||||
# import healpy as hp #maybe move to astropy-healpix cone_search_skycoord
|
||||
from astropy_healpix import HEALPix
|
||||
from astropy.coordinates import SkyCoord
|
||||
from astropy import units as u
|
||||
|
||||
@ -55,6 +56,7 @@ class ConeSearchView(APIView):
|
||||
ra = float(request.query_params.get('ra'))
|
||||
dec = float(request.query_params.get('dec'))
|
||||
radius = float(request.query_params.get('radius'))
|
||||
order = str(request.query_params.get('order'))
|
||||
except (TypeError, ValueError):
|
||||
return Response({"error": "Invalid parameters"}, status=status.HTTP_400_BAD_REQUEST)
|
||||
# radius = float(radius)
|
||||
@ -66,9 +68,12 @@ class ConeSearchView(APIView):
|
||||
center = SkyCoord(ra=ra*u.deg, dec=dec*u.deg, frame='icrs')
|
||||
|
||||
#fetch healpix indices in the specified disc
|
||||
healpix_indices = self.get_healpix_indices(ra, dec, radius, nside)
|
||||
healpix_indices = self.get_healpix_indices(ra, dec, radius, nside, order)
|
||||
#fetch all objects from those healpixes
|
||||
objects = GaiaSource.objects.filter(healpix_ring_index__in=healpix_indices)
|
||||
if order == 'ring':
|
||||
objects = GaiaSource.objects.filter(healpix_ring_index__in=healpix_indices)
|
||||
elif order == 'nested':
|
||||
objects = GaiaSource.objects.filter(healpix_nested_index__in=healpix_indices)
|
||||
|
||||
results = [] #initialize the results list
|
||||
|
||||
@ -93,18 +98,14 @@ class ConeSearchView(APIView):
|
||||
|
||||
|
||||
@staticmethod
|
||||
def get_healpix_indices(ra, dec, radius, nside):
|
||||
def get_healpix_indices(ra, dec, radius, nside, order):
|
||||
|
||||
# Create HEALPix object
|
||||
healpix = HEALPix(nside=nside, order=order, frame='icrs')
|
||||
|
||||
# Convert the input coordinates to a SkyCoord object
|
||||
center = SkyCoord(ra=ra*u.deg, dec=dec*u.deg, frame='icrs')
|
||||
|
||||
# Convert the center coordinates to HEALPix vector
|
||||
vec = hp.ang2vec(center.ra.deg, center.dec.deg, lonlat=True)
|
||||
|
||||
# Find the pixels within the given radius
|
||||
indices = hp.query_disc(nside, vec, np.radians(radius))
|
||||
return indices
|
||||
|
||||
|
||||
|
||||
|
||||
indices = healpix.cone_search_skycoord(center, radius*u.deg)
|
||||
return indices
|
Loading…
x
Reference in New Issue
Block a user