api work
This commit is contained in:
parent
0bbc34086f
commit
4ae88fd94b
2
urls.py
2
urls.py
@ -3,7 +3,7 @@ from .views import ConeSearchView
|
||||
|
||||
urlpatterns = [
|
||||
path(
|
||||
'cone_search/<float:ra>/<float:dec>/<float:radius>',
|
||||
'cone_search/<str:ra>/<str:dec>/<str:radius>',
|
||||
ConeSearchView.as_view(),
|
||||
name = 'cone_search'
|
||||
),
|
||||
|
29
views.py
29
views.py
@ -13,6 +13,19 @@ from astropy import units as u
|
||||
|
||||
class ConeSearchView(APIView):
|
||||
|
||||
@staticmethod
|
||||
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)
|
||||
|
||||
# Find the pixels within the given radius
|
||||
indices = hp.query_disc(nside, vec, np.radians(radius))
|
||||
return indices
|
||||
|
||||
def get(self, request, ra, dec, radius):
|
||||
radius = float(radius)
|
||||
ra = float(ra)
|
||||
@ -23,7 +36,7 @@ class ConeSearchView(APIView):
|
||||
center = SkyCoord(ra=ra*u.deg, dec=dec*u.deg, frame='icrs')
|
||||
|
||||
#fetch healpix indices in the specified disc
|
||||
healpix_indices = get_healpix_indices(ra, dec, radius, nside)
|
||||
healpix_indices = self.get_healpix_indices(ra, dec, radius, nside)
|
||||
#fetch all objects from those healpixes
|
||||
objects = GaiaSource.objects.filter(healpix_ring_index__in=healpix_indices)
|
||||
|
||||
@ -39,7 +52,7 @@ class ConeSearchView(APIView):
|
||||
|
||||
separation = center.separation(source_coordinates)
|
||||
|
||||
if separation.degrees <= radius:
|
||||
if separation.degree <= radius:
|
||||
|
||||
results.append(obj)
|
||||
|
||||
@ -47,16 +60,6 @@ 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)
|
||||
|
||||
# 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