diff --git a/urls.py b/urls.py index 8b13789..357a23b 100644 --- a/urls.py +++ b/urls.py @@ -1 +1,10 @@ +from django.urls import path +from .views import ConeSearchView +urlpatterns = [ + path( + 'cone_search///', + ConeSearchView.as_view(), + name = 'cone_search' + ), +] \ No newline at end of file diff --git a/views.py b/views.py index fc31c79..224a45f 100644 --- a/views.py +++ b/views.py @@ -19,6 +19,7 @@ class ConeSearchView(APIView): dec = float(dec) nside = 2048 + #create skycoord for the center of search center = SkyCoord(ra=ra*u.deg, dec=dec*u.deg, frame='icrs') #fetch healpix indices in the specified disc @@ -26,7 +27,7 @@ class ConeSearchView(APIView): #fetch all objects from those healpixes objects = GaiaSource.objects.filter(healpix_ring_index__in=healpix_indices) - results = [] + results = [] #initialize the results list for obj in objects: @@ -38,7 +39,7 @@ class ConeSearchView(APIView): separation = center.separation(source_coordinates) - if separation <= radius: + if separation.degrees <= radius: results.append(obj) @@ -47,10 +48,13 @@ class ConeSearchView(APIView): return Response(serializer.data, status=status.HTTP_200_OK) def get_healpix_indices(ra, dec, radius, nside): + # 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) + 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