diff --git a/views.py b/views.py index 373d55c..34e0593 100644 --- a/views.py +++ b/views.py @@ -1,32 +1,56 @@ from rest_framework.views import APIView +#from rest_framework.generics import GenericAPIView from rest_framework.response import Response from rest_framework import status from .models import GaiaSource from .serializers import GaiaSourceSerializer +from drf_spectacular.utils import extend_schema, OpenApiResponse, OpenApiParameter + import numpy as np import healpy as hp from astropy.coordinates import SkyCoord from astropy import units as u + + class ConeSearchView(APIView): - @staticmethod - def get_healpix_indices(ra, dec, radius, nside): + serializer_class = GaiaSourceSerializer - # Convert the input coordinates to a SkyCoord object - center = SkyCoord(ra=ra*u.deg, dec=dec*u.deg, frame='icrs') + @extend_schema( - # Convert the center coordinates to HEALPix vector - vec = hp.ang2vec(center.ra.deg, center.dec.deg, lonlat=True) + description = "GAIA DR3 cone search using healpix indexation. ra, dec, radius in decimal degrees.", - # Find the pixels within the given radius - indices = hp.query_disc(nside, vec, np.radians(radius)) - return indices + summary = "GAIA DR3 cone search.", + + responses = { + 200: OpenApiResponse(response=GaiaSourceSerializer(many=True), description="Successful Response"), + 400: OpenApiResponse(description="Bad Request"), + 404: OpenApiResponse(description="Not Found") + }, + + # parameters=[ + # OpenApiParameter( + # name='ra', description='Right Ascension in decimal degrees', required=True, type=float + # ), + # OpenApiParameter( + # name='dec', description='Declination in decimal degrees', required=True, type=float + # ), + # OpenApiParameter( + # name='radius', description='Search radius in decimal degrees', required=True, type=float + # ) + # ], + tags=["GAIA"], + + ) + + def get(self, request, ra, dec, radius): + radius = float(radius) ra = float(ra) dec = float(dec) @@ -62,4 +86,19 @@ 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 + + +