added api endpoint
This commit is contained in:
parent
c0c520c6ac
commit
0bbc34086f
9
urls.py
9
urls.py
@ -1 +1,10 @@
|
||||
from django.urls import path
|
||||
from .views import ConeSearchView
|
||||
|
||||
urlpatterns = [
|
||||
path(
|
||||
'cone_search/<float:ra>/<float:dec>/<float:radius>',
|
||||
ConeSearchView.as_view(),
|
||||
name = 'cone_search'
|
||||
),
|
||||
]
|
10
views.py
10
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user